Skip to content

Commit

Permalink
remove details from loggin when object is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger authored and wardpeet committed Sep 1, 2021
1 parent 8c610d0 commit 3f686a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ Details:
https://images.ctfassets.net/stop-retry-after-3-attempts.jpg
---
Reason: Exceeded maximum retry attempts (3)
---
Details:
{}
---"
`)

Expand Down
33 changes: 22 additions & 11 deletions packages/gatsby-source-contentful/src/fetch-contentful-asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,30 @@ export async function fetchContentfulAsset({
`---`,
`Reason: ${err.message}`,
`---`,
`Details:`,
JSON.stringify({
headers: restArgs.headers,
httpOpts: restArgs.httpOpts,
code: err.code,
statusCode: err.statusCode,
options: err.options,
request: err.request,
response: err.response,
}),
`---`,
].join(`\n`)

// Gather details about what went wrong from the error object and the request
const details = Object.entries({
headers: restArgs.headers,
httpOpts: restArgs.httpOpts,
code: err.code,
statusCode: err.statusCode,
options: err.options,
request: err.request,
response: err.response,
})
// Remove undefined values
.reduce((a, [k, v]) => (v === undefined ? a : ((a[k] = v), a)), {})

if (Object.keys(details).length) {
err.message = [
err.message,
`Details:`,
JSON.stringify(details),
`---`,
].join(`\n`)
}

err.url = url
err.headers = restArgs.headers
err.httpOpts = restArgs.httpOpts
Expand Down

0 comments on commit 3f686a0

Please sign in to comment.