Skip to content

Commit

Permalink
fix(gatsby-source-filesystem): fix unhandled rejection by returning p…
Browse files Browse the repository at this point in the history
…romise chain (#14180)
  • Loading branch information
wardpeet authored and DSchau committed May 20, 2019
1 parent e4b27b3 commit 53c91b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ describe(`create-remote-file-node`, () => {
pipe: jest.fn(() => gotMock),
on: jest.fn((mockType, mockCallback) => {
if (mockType === type) {
// got throws on 404/500 so we mimic this behaviour
if (response.statusCode === 404) {
throw new Error(`Response code 404 (Not Found)`)
}

mockCallback(response)
}

Expand Down Expand Up @@ -177,7 +182,7 @@ describe(`create-remote-file-node`, () => {
)
})

it(`passes custom http heades, if defined`, async () => {
it(`passes custom http header, if defined`, async () => {
await setup({
httpHeaders: {
Authorization: `Bearer foobar`,
Expand All @@ -193,6 +198,19 @@ describe(`create-remote-file-node`, () => {
})
)
})

it(`fails when 404 is given`, async () => {
expect.assertions(1)
try {
await setup({}, `response`, { statusCode: 404 })
} catch (err) {
expect(err).toEqual(
expect.stringContaining(
`failed to process https://images.whatever.com/real-image-trust-me`
)
)
}
})
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,11 @@ module.exports = ({
name,
})

fileDownloadPromise.then(() => bar.tick())
processingCache[url] = fileDownloadPromise.then(node => {
bar.tick()

processingCache[url] = fileDownloadPromise
return fileDownloadPromise
return node
})

return processingCache[url]
}

0 comments on commit 53c91b5

Please sign in to comment.