Handle API error and clear result when not found (#8)
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
This commit is contained in:
+8
-1
@@ -39,12 +39,19 @@ function find() {
|
|||||||
signal: inflight.signal,
|
signal: inflight.signal,
|
||||||
body: "{\"api\":\"GithubIDContributions\",\"payload\":{\"github_id\":\"" + user + "\"}}",
|
body: "{\"api\":\"GithubIDContributions\",\"payload\":{\"github_id\":\"" + user + "\"}}",
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => {
|
||||||
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
statusUpdate("", "info");
|
statusUpdate("", "info");
|
||||||
let score = data.contributions;
|
let score = data.contributions;
|
||||||
if (!score) {
|
if (!score) {
|
||||||
statusUpdate(`Failed to get devstats score for '${user}'.\nEither user doesn't exist or no contributions recorded.`, "error");
|
statusUpdate(`Failed to get devstats score for '${user}'.\nEither user doesn't exist or no contributions recorded.`, "error");
|
||||||
|
result.innerHTML = "";
|
||||||
|
subResult.innerHTML = "";
|
||||||
|
rawResultsWrapper.classList.add('hidden');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
result.innerHTML = score;
|
result.innerHTML = score;
|
||||||
subResult.innerHTML = `Issues: ${data.issues} | PRs: ${data.prs}`;
|
subResult.innerHTML = `Issues: ${data.issues} | PRs: ${data.prs}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user