Skip to content

Commit 1afb3a3

Browse files
piehm-allanson
authored andcommitted
[gatsby-source-filesystem] add fs error handling, bump got retry attemps count (#5375)
* [gatsby-source-filesystem] catch fs stream errors * [gatsby-source-filesystem] bump got retries from default 2 to 5 * normalize reject payload
1 parent 0f4355c commit 1afb3a3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/gatsby-source-filesystem/src/create-remote-file-node.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,23 @@ async function pushToQueue(task, cb) {
132132
*/
133133
const requestRemoteNode = (url, headers, tmpFilename, filename) =>
134134
new Promise((resolve, reject) => {
135-
const responseStream = got.stream(url, { ...headers, timeout: 30000 })
135+
const responseStream = got.stream(url, {
136+
...headers,
137+
timeout: 30000,
138+
retries: 5,
139+
})
136140
const fsWriteStream = fs.createWriteStream(tmpFilename)
137141
responseStream.pipe(fsWriteStream)
138142
responseStream.on(`downloadProgress`, pro => console.log(pro))
139143

140144
// If there's a 400/500 response or other error.
141145
responseStream.on(`error`, (error, body, response) => {
142146
fs.removeSync(tmpFilename)
143-
reject({ error, body, response })
147+
reject(error)
148+
})
149+
150+
fsWriteStream.on(`error`, error => {
151+
reject(error)
144152
})
145153

146154
responseStream.on(`response`, response => {

0 commit comments

Comments
 (0)