Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function handleError(error: unknown) {

if (NETWORK_ERROR_CODES.includes(error.status)) {
// status in 500...599 range - server had an error, request might be retryed.
throw new AuthRetryableFetchError(_getErrorMessage(error), error.status)
throw new AuthRetryableFetchError(error.statusText, error.status)
}

let data: any
Expand Down
20 changes: 20 additions & 0 deletions test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ describe('fetch', () => {
await server.start()
})

test('should throw AuthRetryableFetchError when response is a network error', async () => {
const route = server
.get('/')
.mockImplementationOnce((ctx) => {
ctx.status = 504
ctx.statusText = 'Gateway Timeout'
ctx.body = 'Gateway Timeout'
})
.mockImplementation((ctx) => {
ctx.status = 200
})

const url = server.getURL().toString()
const result = _request(fetch, 'GET', url)
await expect(result).rejects.toBeInstanceOf(AuthRetryableFetchError)
await expect(result).rejects.toMatchObject({ status: 504, message: 'Gateway Timeout' })

expect(route).toHaveBeenCalledTimes(1)
})

test('should work with custom fetch implementation', async () => {
const customFetch = (async () => {
return {
Expand Down