Best way to handle empty bodies in error response? #438
Unanswered
dasveloper
asked this question in
Q&A
Replies: 1 comment
-
Related? #415 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently I use KY like this to fetch my data and get either the success or error json:
This works great for all "planned errors", but in the case where somehow I hit a route that doesn't exist or the body is empty,
error.response.json()
throws an error. I can solve this by adding another catch like this:However, that is obviously really ugly. Is there a clean way to handle this? Or at least a way I can move that into a ky hook so that I don't have to replicate that everywhere?
Beta Was this translation helpful? Give feedback.
All reactions