Skip to content

Commit e989d06

Browse files
committed
feat: show details in error message
1 parent b560051 commit e989d06

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/headers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export const NF_ERROR = 'x-nf-error'
12
export const NF_REQUEST_ID = 'x-nf-request-id'

src/main.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { MockFetch } from '../test/mock_fetch.js'
88
import { base64Encode, streamToString } from '../test/util.js'
99

1010
import { MissingBlobsEnvironmentError } from './environment.js'
11-
import { NF_REQUEST_ID } from './headers.js'
11+
import { NF_ERROR, NF_REQUEST_ID } from './headers.js'
1212
import { getDeployStore, getStore, setEnvironmentContext } from './main.js'
1313
import { base64Decode } from './util.js'
1414

@@ -271,9 +271,10 @@ describe('get', () => {
271271
})
272272

273273
test('Throws when an edge URL returns a non-200 status code', async () => {
274+
const errorDetails = 'Missing authorization header'
274275
const mockStore = new MockFetch().get({
275276
headers: { authorization: `Bearer ${edgeToken}` },
276-
response: new Response(null, { status: 401 }),
277+
response: new Response(null, { headers: { [NF_ERROR]: errorDetails }, status: 401 }),
277278
url: `${edgeURL}/${siteID}/site:production/${key}`,
278279
})
279280

@@ -287,7 +288,7 @@ describe('get', () => {
287288
})
288289

289290
await expect(async () => await blobs.get(key)).rejects.toThrowError(
290-
`Netlify Blobs has generated an internal error: 401 response`,
291+
`Netlify Blobs has generated an internal error: ${errorDetails}`,
291292
)
292293

293294
expect(mockStore.fulfilled).toBeTruthy()

src/util.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { NF_REQUEST_ID } from './headers.ts'
1+
import { NF_ERROR, NF_REQUEST_ID } from './headers.ts'
22

33
export class BlobsInternalError extends Error {
44
constructor(res: Response) {
5-
let message = `Netlify Blobs has generated an internal error: ${res.status} response`
5+
const details = res.headers.get(NF_ERROR) ?? `${res.status} response`
6+
7+
let message = `Netlify Blobs has generated an internal error: ${details}`
68

79
if (res.headers.has(NF_REQUEST_ID)) {
810
message += ` (ID: ${res.headers.get(NF_REQUEST_ID)})`

0 commit comments

Comments
 (0)