H
Hono4mo ago
igmtink

How to handle multiple errors in (react query) using (hono rpc)?

How can I handle multiple errors like in my case? I want to display the error on my signup form layout.
5 Replies
Nico
Nico4mo ago
Can you show the full code? The popup is blocking some, also how you set the types for RPC
igmtink
igmtink4mo ago
I want to get the error message from hono, but there's a type error, even the type of ResponseType is { error: string } | { data: string } I want to display on my sign up layout that multiple error like if Username is already exist or Email is already exist
fOfer
fOfer4mo ago
Curious about this I myself had to do this in my useQuery instances on the client side
async (res) => {
switch (res.status) {
case 500:
throw new errors.ParseError(await res.text())
case 200:
return res.json()
case 404:
default:
throw new errors.NotFoundError(await res.text())
}
}
async (res) => {
switch (res.status) {
case 500:
throw new errors.ParseError(await res.text())
case 200:
return res.json()
case 404:
default:
throw new errors.NotFoundError(await res.text())
}
}
Would love to set this at the hc client level Or create a typesafe function that receives the $get or $post return and apply that validation without loosing typesafety
igmtink
igmtink4mo ago
where did you add this code?
Nico
Nico4mo ago
It should go between your response and data variables. You want it before you convert to JSON
Want results from more Discord servers?
Add your server