Skip to content

Commit

Permalink
🥅 Add timeout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stoe committed Feb 14, 2024
1 parent 40ea5b4 commit 36b1cef
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/vartastorage/lib/varta.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ const CREDENTIALS_PATH = join(process.env.PWD, 'vartastorage/credentials.json')
const buf = readFileSync(CREDENTIALS_PATH)
const {user, pwd} = JSON.parse(Buffer.from(buf).toString())

const TIMEOUT_ERROR_CODES = [
'ETIMEDOUT',
'ECONNRESET',
'EADDRINUSE',
'ECONNREFUSED',
'EPIPE',
'ENOTFOUND',
'ENETUNREACH',
'EAI_AGAIN',
]

// run
;(async () => {
try {
Expand All @@ -24,6 +35,9 @@ const {user, pwd} = JSON.parse(Buffer.from(buf).toString())
'API-Version': 1,
Authorization: `Basic ${Buffer.from(`${user}:${pwd}`).toString('base64')}`,
},
timeout: {
request: 10000,
},
})

if (ls !== 200) {
Expand Down Expand Up @@ -65,6 +79,10 @@ const {user, pwd} = JSON.parse(Buffer.from(buf).toString())
}),
)
} catch (error) {
console.error(error.message)
if (error.code && TIMEOUT_ERROR_CODES.includes(error.code)) {
console.error('Varta Storage Portal request timed out')
} else {
console.error(error.message)
}
}
})()

0 comments on commit 36b1cef

Please sign in to comment.