Skip to content

Commit cf348f8

Browse files
committed
Fix bug with assuming there is a response on the error object
1 parent 694724f commit cf348f8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/sync/downloader.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ module.exports = function(mlsSourceName, configBundle, eventEmitter, loggerArg)
133133
}
134134
auth = await ensureAuthIsNotExpired(auth)
135135
let loopCount = 0
136+
const maxLoops = 3
136137
while (!metadataString) {
137138
loopCount++
138139
try {
@@ -156,7 +157,8 @@ module.exports = function(mlsSourceName, configBundle, eventEmitter, loggerArg)
156157
// })
157158
// .catch(catcher('get metadata'))
158159
} catch (error) {
159-
if (loopCount <= 3 && (error.code === 'EAI_AGAIN' || !'debug' || error.response.status >= 500)) {
160+
if (loopCount <= maxLoops
161+
&& (error.code === 'EAI_AGAIN' || !'debug' || (error.response && error.response.status >= 500))) {
160162
// Will loop
161163
console.log(`There was a problem with the request, trying again (${loopCount})`)
162164
} else {
@@ -322,7 +324,8 @@ module.exports = function(mlsSourceName, configBundle, eventEmitter, loggerArg)
322324
}
323325
})
324326
.catch(error => {
325-
if (loopCount <= maxLoops && (error.code === 'EAI_AGAIN' || !'debug' || error.response.status >= 500)) {
327+
if (loopCount <= maxLoops
328+
&& (error.code === 'EAI_AGAIN' || !'debug' || (error.response && error.response.status >= 500))) {
326329
// Will loop
327330
console.log(`There was a problem with the request, trying again (${loopCount})`)
328331
} else {

0 commit comments

Comments
 (0)