You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to know how to handle errors inside the Hono server, so I can get the error within the React Query. What I used to handle the error is this: return c.json({ message: 'Invalid password' }, { status: 401 }) on the Hono server. The problem is the 'onError' option of React Query doesn't catch it, so I used try-catch to pass the error to 'onError'. Normally, when fetching using the standard Fetch API and there's an error, React Query automatically passes it to 'onError'. But when using RPC, it doesn't pass to 'onError', so I'm not sure if the way I handled the error in my API route is correct. It still returns the error message as data, so I used try-catch."
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
What I want is to get the error from server to client using
rpc + react query
trycatch
c.json({ message: 'Invalid password' }, 401)
HTTPException(401, { message: 'Invalid password' })
I want to know how to handle errors inside the Hono server, so I can get the error within the React Query. What I used to handle the error is this:
return c.json({ message: 'Invalid password' }, { status: 401 })
on the Hono server. The problem is the 'onError' option of React Query doesn't catch it, so I used try-catch to pass the error to 'onError'. Normally, when fetching using the standard Fetch API and there's an error, React Query automatically passes it to 'onError'. But when using RPC, it doesn't pass to 'onError', so I'm not sure if the way I handled the error in my API route is correct. It still returns the error message as data, so I used try-catch."Beta Was this translation helpful? Give feedback.
All reactions