Tanmay
Tanmay2w ago

handle client side errors with next.js

how to handle erros
No description
4 Replies
Sara
Sara2w ago
as far as I'm aware, this is a developer caused error, but i think your question is you want to have client errors to not disturb your page: 1. use something like sentry, you get the issues/problems when they happen so you can dedicate your time to fix them or find out what caused them 2. I'd look in here http://nextjs.org/docs/app/getting-started/error-handling for answers without having a third party option. 3. there's a package that I don't remember the name of it was, something react-error-boundary that might help! 4. to actually fix this error, don't use any types, you could pass the id as string in your query and do something like this:
const noteId = ctx.db.normalizedId("notes",id);
if(!noteId){
throw new Erorr("Wrong Id passed") // or return? I'd throw an error
}
// your happy path code here
const noteId = ctx.db.normalizedId("notes",id);
if(!noteId){
throw new Erorr("Wrong Id passed") // or return? I'd throw an error
}
// your happy path code here
but you need to have proper error handling on your client
Getting Started: Error Handling | Next.js
Learn how to display expected errors and handle uncaught exceptions.
Tanmay
TanmayOP2w ago
handle error if no data in db with id
erquhart
erquhart2w ago
Pass “skip” instead of an args object when calling useQuery if the id is undefined. Or you can make the argument optional in your query function and just return early if no id is provided.

Did you find this page helpful?