@@ -24,7 +24,7 @@ export const resolver = <T, Chain, R, E, CatcherResult>(wretch: T & Wretch<T, Ch
2424 const {
2525 _url : url ,
2626 _options : opts ,
27- _fetch : customFetch ,
27+ _fetch,
2828 _errorTransformer : errorTransformer ,
2929 _catchers : _catchers ,
3030 _resolvers : resolvers ,
@@ -39,12 +39,17 @@ export const resolver = <T, Chain, R, E, CatcherResult>(wretch: T & Wretch<T, Ch
3939 let finalUrl = url
4040 const _fetchReq = middlewareHelper ( middlewares ) ( ( url , options ) => {
4141 finalUrl = url
42- const fetchImpl = customFetch || fetch
42+ const fetchImpl = _fetch || fetch
4343 return fetchImpl ( url , options )
4444 } ) ( url , finalOptions )
4545 // Throws on an http error
4646 const referenceError = new Error ( )
4747 const throwingPromise : Promise < void | WretchResponse > = _fetchReq
48+ . catch ( error => {
49+ // Interect fetch errors and mark them with a special symbol so that they can be caught by a matching catcher
50+ error [ FETCH_ERROR ] = true
51+ throw error
52+ } )
4853 . then ( async response => {
4954 if ( ! response . ok ) {
5055 const err = new WretchError ( )
@@ -75,7 +80,7 @@ export const resolver = <T, Chain, R, E, CatcherResult>(wretch: T & Wretch<T, Ch
7580 const catcher =
7681 catchers . get ( error ?. status ) ||
7782 catchers . get ( error ?. name ) ||
78- ( ! ( error instanceof WretchError ) && catchers . get ( FETCH_ERROR ) ) ||
83+ ( error ?. [ FETCH_ERROR ] && catchers . get ( FETCH_ERROR ) ) ||
7984 catchers . get ( CATCHER_FALLBACK )
8085
8186 if ( error . response && errorTransformer ) {
0 commit comments