Skip to content

Commit c6f9c7f

Browse files
authored
undo adding statusText since it is empty in HTTP/2 (#1304)
1 parent f95b576 commit c6f9c7f

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

packages/toolkit/src/query/fetchBaseQuery.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export type FetchBaseQueryError =
6666
*/
6767
status: number
6868
data: unknown
69-
statusText: string
7069
}
7170
| {
7271
/**
@@ -86,10 +85,18 @@ export type FetchBaseQueryError =
8685
**/
8786
status: 'PARSING_ERROR'
8887
originalStatus: number
89-
statusText: string
9088
data: string
9189
error: string
9290
}
91+
| {
92+
/**
93+
* * `"CUSTOM_ERROR"`:
94+
* A custom error type that you can return from your `fetchFn` where another error might not make sense.
95+
**/
96+
status: 'CUSTOM_ERROR'
97+
data?: unknown
98+
error: string
99+
}
93100

94101
function stripUndefined(obj: any) {
95102
if (!isPlainObject(obj)) {
@@ -237,7 +244,6 @@ export function fetchBaseQuery({
237244
error: {
238245
status: 'PARSING_ERROR',
239246
originalStatus: response.status,
240-
statusText: response.statusText,
241247
data: await responseClone.clone().text(),
242248
error: String(e),
243249
},
@@ -254,7 +260,6 @@ export function fetchBaseQuery({
254260
error: {
255261
status: response.status,
256262
data: resultData,
257-
statusText: response.statusText,
258263
},
259264
meta,
260265
}

packages/toolkit/src/query/tests/errorHandling.test.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ describe('fetchBaseQuery', () => {
6767
).resolves.toEqual({
6868
error: {
6969
data: { value: 'error' },
70-
statusText: 'Internal Server Error',
7170
status: 500,
7271
},
7372
meta: {
@@ -118,7 +117,6 @@ describe('query error handling', () => {
118117
isSuccess: false,
119118
error: {
120119
status: 500,
121-
statusText: 'Internal Server Error',
122120
data: { value: 'error' },
123121
},
124122
})
@@ -161,7 +159,6 @@ describe('query error handling', () => {
161159
isSuccess: false,
162160
error: {
163161
status: 500,
164-
statusText: 'Internal Server Error',
165162
data: { value: 'error' },
166163
},
167164
// last data will stay available
@@ -193,7 +190,6 @@ describe('query error handling', () => {
193190
isSuccess: false,
194191
error: {
195192
status: 500,
196-
statusText: 'Internal Server Error',
197193
data: { value: 'error' },
198194
},
199195
})
@@ -261,7 +257,6 @@ describe('mutation error handling', () => {
261257
isSuccess: false,
262258
error: {
263259
status: 500,
264-
statusText: 'Internal Server Error',
265260
data: { value: 'error' },
266261
},
267262
})
@@ -313,7 +308,6 @@ describe('mutation error handling', () => {
313308
isSuccess: false,
314309
error: {
315310
status: 500,
316-
statusText: 'Internal Server Error',
317311
data: { value: 'error' },
318312
},
319313
})
@@ -351,7 +345,6 @@ describe('mutation error handling', () => {
351345
isSuccess: false,
352346
error: {
353347
status: 500,
354-
statusText: 'Internal Server Error',
355348
data: { value: 'error' },
356349
},
357350
})
@@ -587,7 +580,6 @@ describe('error handling in a component', () => {
587580
expect(result).toMatchObject({
588581
error: {
589582
status: 500,
590-
statusText: 'Internal Server Error',
591583
data: { value: 'error' },
592584
},
593585
})
@@ -625,7 +617,6 @@ describe('error handling in a component', () => {
625617
const unwrappedPromise = mutationqueryFulfilled!.unwrap()
626618
expect(unwrappedPromise).rejects.toMatchObject({
627619
status: 500,
628-
statusText: 'Internal Server Error',
629620
data: { value: 'error' },
630621
})
631622
})

packages/toolkit/src/query/tests/fetchBaseQuery.test.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ describe('fetchBaseQuery', () => {
123123
expect(res.meta?.response).toBeInstanceOf(Object)
124124
expect(res.error).toEqual({
125125
status: 500,
126-
statusText: 'Internal Server Error',
127126
data: { value: 'error' },
128127
})
129128
})
@@ -202,7 +201,6 @@ describe('fetchBaseQuery', () => {
202201
status: 'PARSING_ERROR',
203202
error: 'SyntaxError: Unexpected token h in JSON at position 1',
204203
originalStatus: 200,
205-
statusText: 'OK',
206204
data: `this is not json!`,
207205
})
208206
})
@@ -230,7 +228,6 @@ describe('fetchBaseQuery', () => {
230228
expect(res.meta?.response).toBeInstanceOf(Object)
231229
expect(res.error).toEqual({
232230
status: 500,
233-
statusText: 'Internal Server Error',
234231
data: `this is not json!`,
235232
})
236233
})
@@ -260,7 +257,6 @@ describe('fetchBaseQuery', () => {
260257
status: 'PARSING_ERROR',
261258
error: 'SyntaxError: Unexpected token h in JSON at position 1',
262259
originalStatus: 500,
263-
statusText: 'Internal Server Error',
264260
data: `this is not json!`,
265261
})
266262
})
@@ -458,7 +454,6 @@ describe('fetchBaseQuery', () => {
458454

459455
expect(res.error).toEqual({
460456
status: 200,
461-
statusText: 'OK',
462457
data: {
463458
success: false,
464459
message: 'This returns a 200 but is really an error',
@@ -692,11 +687,11 @@ describe('fetchFn', () => {
692687
ok: true,
693688
status: 200,
694689
text: async () => `{ "url": "mock-return-url" }`,
695-
clone: () => fakeResponse
690+
clone: () => fakeResponse,
696691
}
697692

698-
const spiedFetch = jest.spyOn(window, 'fetch');
699-
spiedFetch.mockResolvedValueOnce(fakeResponse as any);
693+
const spiedFetch = jest.spyOn(window, 'fetch')
694+
spiedFetch.mockResolvedValueOnce(fakeResponse as any)
700695

701696
const { data } = await baseQuery(
702697
{ url: '/echo' },
@@ -707,9 +702,9 @@ describe('fetchFn', () => {
707702
},
708703
{}
709704
)
710-
expect(data).toEqual({url: 'mock-return-url'})
705+
expect(data).toEqual({ url: 'mock-return-url' })
711706

712-
spiedFetch.mockClear();
707+
spiedFetch.mockClear()
713708
})
714709
})
715710

packages/toolkit/src/query/tests/queryLifecycle.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ describe.each([['query'], ['mutation']] as const)(
9898
expect(onError).toHaveBeenCalledWith({
9999
error: {
100100
status: 500,
101-
statusText: 'Internal Server Error',
102101
data: { value: 'error' },
103102
},
104103
isUnhandledError: false,
@@ -221,7 +220,6 @@ test('query: getCacheEntry (error)', async () => {
221220
error: {
222221
data: { value: 'error' },
223222
status: 500,
224-
statusText: 'Internal Server Error',
225223
},
226224
endpointName: 'injected',
227225
isError: true,
@@ -340,7 +338,6 @@ test('mutation: getCacheEntry (error)', async () => {
340338
error: {
341339
data: { value: 'error' },
342340
status: 500,
343-
statusText: 'Internal Server Error',
344341
},
345342
endpointName: 'injected',
346343
isError: true,

0 commit comments

Comments
 (0)