Skip to content

Commit

Permalink
Add explicit timeout error message from GitHub API
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Apr 14, 2021
1 parent 9899c90 commit 11a7bed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions source/app/web/instance.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@
console.debug(`metrics/app/${login} > 404 (user/organization not found)`)
return res.status(404).send("Not found: unknown user or organization")
}
//GitHub failed request
if ((error instanceof Error)&&(/this may be the result of a timeout, or it could be a GitHub bug/i.test(error.errors?.[0]?.message))) {
console.debug(`metrics/app/${login} > 502 (bad gateway from GitHub)`)
const {request} = error.errors[0].message.match(/`(?<request>[\w:]+)`/)?.groups ?? null
return res.status(502).send(`Bad Gateway: GitHub failed to execute request ${request} (this may be the result of a timeout, or it could be a GitHub bug)`)
}
//General error
console.error(error)
return res.status(500).send("Internal Server Error: failed to process metrics correctly")
Expand Down Expand Up @@ -278,6 +284,12 @@
console.debug(`metrics/app/${login} > 400 (bad request)`)
return res.status(400).send("Bad request: unsupported template")
}
//GitHub failed request
if ((error instanceof Error)&&(/this may be the result of a timeout, or it could be a GitHub bug/i.test(error.errors?.[0]?.message))) {
console.debug(`metrics/app/${login} > 502 (bad gateway from GitHub)`)
const {request} = error.errors[0].message.match(/`(?<request>[\w:]+)`/)?.groups ?? null
return res.status(502).send(`Bad Gateway: GitHub failed to execute request ${request} (this may be the result of a timeout, or it could be a GitHub bug)`)
}
//General error
console.error(error)
return res.status(500).send("Internal Server Error: failed to process metrics correctly")
Expand Down
2 changes: 1 addition & 1 deletion source/app/web/statics/about/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
this.metrics = (await axios.get(`/about/query/${this.user}`)).data
}
catch (error) {
this.error = error
this.error = {code:error.response.status, message:error.response.data}
}
finally {
this.pending = false
Expand Down

0 comments on commit 11a7bed

Please sign in to comment.