Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit 3fc1749

Browse files
authored
Merge pull request #20 from netlify/improve-fetch-errors
Attach data to fetch errors
2 parents 91d950d + 96e3095 commit 3fc1749

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/open-api/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,17 @@ exports.generateMethod = method => {
8080
opts.method = method.verb.toUpperCase()
8181

8282
// TODO: Use micro-api-client when it supports node-fetch
83-
const response = await fetch(path, opts)
83+
let response
84+
try {
85+
response = await fetch(path, opts)
86+
} catch (e) {
87+
/* istanbul ignore next */
88+
e.name = 'FetchError'
89+
e.url = path
90+
e.data = Object.assign({}, opts)
91+
delete e.data.Authorization
92+
throw e
93+
}
8494

8595
const contentType = response.headers.get('Content-Type')
8696

0 commit comments

Comments
 (0)