Generic response handler for hono/client #2972
Unanswered
paolostyle
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I need some help figuring out a way to handle errors when using
hono/client
. Generally my API is purely JSON based and it either responds with a 2xx or 4xx. So for example my route might look like this:This one actually showcases another problem but I believe #2719 would fix it.
Regardless, my issue is that I'm generating a
.d.ts
file which I can later use in a separate frontend repo and I'm not sure how the order of the responses is determined, but it might be either:or
I don't know how it's determined, the order of responses in the implementation doesn't seem to matter, sometimes it's one way, sometimes the other (usually 200 is first). In general I believe this should not matter, or at least I thought so.
I wrote a generic function that would allow me to not handle the error response every time (I use the
hc
withreact-query
so I need to throw on 4xx/5xx to get proper error handling):The problem is that it works great if the 200 response is first in the union in
d.ts
, but if 401 is first, it doesn't work:It's pretty shocking to me and it's probably not an issue with Hono itself but you guys are TypeScript magicians so perhaps you'll have an idea how to solve it, for now the only solution is to just copy-paste the contents of that
responseHandler
function to.then()
and then it works. But it's really baffling why that happens.Beta Was this translation helpful? Give feedback.
All reactions