insomnia
insomnia copied to clipboard
Fetch error handing revisited
motivation: inconsistency in how the fetch errors were being parsed and evaluated, eg json is parsed twice in order to get the error message in one place but not another.
goal: type the output of insomniaFetch when a known backend error message is returned, and flatten the try catch if else nesting complexity of insomniaFetch
options:
- use a custom Error type, with both message and errorType eg ResponseFailError but with more
- return
Promise<T> | Promise<{message:string,errorType:string}> - return an Error/ErrorCause with the api error within
This PR is meant to push this discussion with: @yaoweiprc @gatzjames
Using the exception and wrapping it has some rough edges in nodejs/chromium space because they dont both have error cause implementations.
TODO:
- [ ] discuss error typing options with api team
- [ ] standardise the way we deal with these within the app and website at a function typing level