insomnia icon indicating copy to clipboard operation
insomnia copied to clipboard

Fetch error handing revisited

Open jackkav opened this issue 1 year ago • 0 comments

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:

  1. use a custom Error type, with both message and errorType eg ResponseFailError but with more
  2. return Promise<T> | Promise<{message:string,errorType:string}>
  3. 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

jackkav avatar Oct 15 '24 08:10 jackkav