mirror of
https://github.com/status-im/sourcecred.git
synced 2025-01-28 21:34:56 +00:00
Improve error messages when GitHub query fails (#536)
Currently, the GitHub graph fetcher will characteristically fail if: 1. it times out GitHub's server 2. it triggers the semidocumented abuse detection mechanism In case 1, an intelligible error is posted to the console. In case 2, it produces an unintelligible TypeError, because the response is not a valid GraphQL response (the error field is not populated; it has a custom message instead). As of this commit, we gracefully catch both cases, and print a message to console directing the user to #350, which has context on GitHub query failures. This new catch works because in case 2, the data field is empty, so we now properly recognize `x.data === undefined` as an error case. Thanks to @wchargin for the investigatory work behind this commit. Fixes #223. Test plan: We don't have unit tests that cover this case, but I did manually test it by asking GitHub to fetch `ipfs/go-ipfs`, which consistently fails. I also tested it by using an invalid length-40 GitHub API token.
This commit is contained in:
parent
deaba09d00
commit
b61b8fbdb8
@ -74,7 +74,15 @@ function postQuery({body, variables}, token) {
|
||||
})
|
||||
.then((x) => x.json())
|
||||
.then((x) => {
|
||||
if (x.errors) {
|
||||
if (x.errors || x.data === undefined) {
|
||||
console.error(
|
||||
"GitHub query failed! We're tracking these issues at " +
|
||||
"https://github.com/sourcecred/sourcecred/issues/350.\n" +
|
||||
"If the error is a timeout or abuse rate limit, you can " +
|
||||
"try loading a smaller repo, or trying again in a few minutes.\n" +
|
||||
"The actual failed response can be found below:\n" +
|
||||
"================================================="
|
||||
);
|
||||
return Promise.reject(x);
|
||||
}
|
||||
return Promise.resolve(x.data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user