Skip to content
Merged
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/error-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const isApiErrorResponse = (

if (headers == null) return false

const contentType = headers['Content-Type']
const contentType = headers['content-type']
if (
typeof contentType === 'string' &&
!contentType.startsWith('application/json')
Expand Down
32 changes: 31 additions & 1 deletion test/seam/connect/http-error.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
import test from 'ava'
import { AxiosError } from 'axios'
import { AxiosError, AxiosHeaders } from 'axios'
import { getTestServer } from 'fixtures/seam/connect/api.js'

import {
errorInterceptor,
SeamHttp,
SeamHttpApiError,
SeamHttpInvalidInputError,
SeamHttpUnauthorizedError,
} from '@seamapi/http/connect'

test('SeamHttp: preserves AxiosError for JSON-shaped non-JSON response', async (t) => {
const data = {
error: {
type: 'bad_gateway',
message: 'A middlebox returned this error page',
},
}
const err = new AxiosError(
'Request failed with status code 502',
AxiosError.ERR_BAD_RESPONSE,
undefined,
undefined,
{
data,
status: 502,
statusText: 'Bad Gateway',
headers: new AxiosHeaders({ 'content-type': 'text/html; charset=utf-8' }),
config: { headers: new AxiosHeaders() },
},
)

const thrown = await t.throwsAsync(errorInterceptor(err), {
instanceOf: AxiosError,
})

t.is(thrown, err)
t.deepEqual(thrown.response?.data, data)
})

test('SeamHttp: throws AxiosError on non-standard response', async (t) => {
const { seed, endpoint } = await getTestServer(t)

Expand Down
Loading