Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(core): Handle fetch rejections and pass to makeErrorResult (#3131)

authored by

Phil Pluckthun and committed by
GitHub
9cdb74b0 29ad3d63

+24 -5
+5
.changeset/eight-kangaroos-wave.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Handle `fetch` rejections in `makeFetchSource` and properly hand them over to `CombinedError`s.
+13
packages/core/src/internal/fetchSource.test.ts
··· 106 106 }); 107 107 }); 108 108 109 + it('handles network errors', async () => { 110 + const error = new Error('test'); 111 + fetch.mockRejectedValue(error); 112 + 113 + const fetchOptions = {}; 114 + const data = await pipe( 115 + makeFetchSource(queryOperation, 'https://test.com/graphql', fetchOptions), 116 + toPromise 117 + ); 118 + 119 + expect(data).toHaveProperty('error.networkError', error); 120 + }); 121 + 109 122 it('returns error data', async () => { 110 123 const fetchOptions = {}; 111 124 const data = await pipe(
+6 -5
packages/core/src/internal/fetchSource.ts
··· 107 107 let networkMode = true; 108 108 let abortController: AbortController | void; 109 109 let result: OperationResult | null = null; 110 - let response: Response; 110 + let response: Response | void; 111 111 112 112 try { 113 113 if (typeof AbortController !== 'undefined') { ··· 151 151 152 152 yield makeErrorResult( 153 153 operation, 154 - (response!.status < 200 || response!.status >= 300) && 155 - response!.statusText 156 - ? new Error(response!.statusText) 154 + response && 155 + (response.status < 200 || response.status >= 300) && 156 + response.statusText 157 + ? new Error(response.statusText) 157 158 : error, 158 - response! 159 + response 159 160 ); 160 161 } finally { 161 162 if (abortController) abortController.abort();