redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Test Failure: Mismatch in Error Message Formatting for Non-JSON Response in fetchBaseQuery

Open Adagedo opened this issue 5 months ago • 2 comments

When running tests for the FetchBaseQuery with a non-JSON body, there is a mismatch in the expected and received error messages. Specifically, the error formatting differs in how it handles unexpected tokens in the response.

Expected Error

"error": "SyntaxError: Unexpected token h in JSON at position 1"

Recieved Error

"error": "SyntaxError: Unexpected token 'h', \"this is not json!\" is not valid JSON"

Test Case: This occurs in the test fetchBaseQuery › non-JSON-body › success: should fail gracefully (default="json" responseHandler) at line 176 in src/query/tests/fetchBaseQuery.test.tsx.

       174 |       expect(res.meta?.request).toBeInstanceOf(Request)
➤ YN0000:       175 |       expect(res.meta?.response).toBeInstanceOf(Object)
➤ YN0000:     > 176 |       expect(res.error).toEqual({
➤ YN0000:           |                         ^
➤ YN0000:       177 |         status: 'PARSING_ERROR',
➤ YN0000:       178 |         error: 'SyntaxError: Unexpected token h in JSON at position 1',
➤ YN0000:       179 |         originalStatus: 200,
➤ YN0000: 

Impact: While this test failure does not affect runtime behavior, it might introduce inconsistencies between the expected and actual error handling, potentially impacting robustness in error reporting. This mismatch may cause confusion when debugging errors in production, as error messages are not formatted as expected.

Adagedo avatar Sep 19 '24 16:09 Adagedo