Skip to content

Commit

Permalink
🐛 Better error catching precedence
Browse files Browse the repository at this point in the history
Fixes #155
  • Loading branch information
elbywan committed Dec 9, 2022
1 parent 3ffd0d3 commit 107fc71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ export const resolver = <T, Chain, R>(wretch: T & Wretch<T, Chain, R>) => {
const error = err.__wrap || err

const catcher =
err.__wrap && catchers.has(FETCH_ERROR) ? catchers.get(FETCH_ERROR) :
(catchers.get(error.status) || catchers.get(error.name))
catchers.get(error.name) || (
err.__wrap && catchers.has(FETCH_ERROR)
? catchers.get(FETCH_ERROR)
: catchers.get(error.status)
)

if (catcher)
return catcher(error, wretch)
Expand Down
1 change: 1 addition & 0 deletions test/node/wretch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ describe("Wretch", function () {
.addon(AbortAddon())
.get()
.setTimeout(100)
.fetchError(() => { /* ignore - tests precendence */ })
.onAbort(handleError)
.res()

Expand Down

0 comments on commit 107fc71

Please sign in to comment.