mirror of
https://github.com/status-im/sourcecred.git
synced 2025-01-13 14:14:57 +00:00
Quicker failure and description when invalid token supplied (#1161)
Fixes #1156 When users export a GitHub API token that has insufficient privleges or has been revoked, we have been using a catch all error with retry to handle it. This change adds a new error type for bad credentials and does not retry. Test plan: There are no unit tests that cover this, however, you can test the change by supplying a revoked token and attempting to load a GitHub repo.
This commit is contained in:
parent
ad2470e5c6
commit
1fbf8cd587
@ -2,6 +2,7 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Fail quicker and with information when using invalid GH token (#1161)
|
||||
- Allow the user to save or upload weight settings (#1150)
|
||||
- Allow tweaking weights on a per-node basis (#1143)
|
||||
- Add the `pagerank` command (#1114)
|
||||
|
@ -83,6 +83,7 @@ type GithubResponseError =
|
||||
| {|+type: "GRAPHQL_ERROR", retry: false, error: mixed|}
|
||||
| {|+type: "RATE_LIMIT_EXCEEDED", retry: false, error: mixed|}
|
||||
| {|+type: "GITHUB_INTERNAL_EXECUTION_ERROR", retry: true, error: mixed|}
|
||||
| {|+type: "BAD_CREDENTIALS", retry: false, error: mixed|}
|
||||
| {|+type: "NO_DATA", retry: true, error: mixed|};
|
||||
|
||||
// Fetch against the GitHub API with the provided options, returning a
|
||||
@ -126,10 +127,20 @@ function tryGithubFetch(fetch, fetchOptions): Promise<any> {
|
||||
}
|
||||
}
|
||||
if (x.data === undefined) {
|
||||
// See https://github.com/sourcecred/sourcecred/issues/350.
|
||||
return Promise.reject(
|
||||
({type: "NO_DATA", retry: true, error: x}: GithubResponseError)
|
||||
);
|
||||
if (x.message && x.message.includes("Bad credentials")) {
|
||||
return Promise.reject(
|
||||
({
|
||||
type: "BAD_CREDENTIALS",
|
||||
retry: false,
|
||||
error: x,
|
||||
}: GithubResponseError)
|
||||
);
|
||||
} else {
|
||||
// See https://github.com/sourcecred/sourcecred/issues/350
|
||||
return Promise.reject(
|
||||
({type: "NO_DATA", retry: true, error: x}: GithubResponseError)
|
||||
);
|
||||
}
|
||||
}
|
||||
return Promise.resolve(x.data);
|
||||
}),
|
||||
@ -205,6 +216,11 @@ export async function postQuery(
|
||||
case "FETCH_ERROR":
|
||||
// Network error; no need for additional commentary.
|
||||
break;
|
||||
case "BAD_CREDENTIALS":
|
||||
console.error(
|
||||
"An invalid token was supplied ($SOURCECRED_GITHUB_TOKEN). This is mostly likely caused by supplying a revoked token."
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new Error((type: empty));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user