Skip to content

Commit f5aec8f

Browse files
committed
Halt promise if user is not logged in.
1 parent fa3a0e6 commit f5aec8f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

GitHubApi.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class GitHubApi{
3636
if(typeof init.body === 'object'){
3737
init.body = JSON.stringify(init.body);
3838
}
39-
return await fetch(new Request('https://api.github.com/'+path, init)).then(response => {
39+
return await fetch(new Request('https://api.github.com/'+path, init)).then(async response => {
4040
if(localStorage.getItem('GitHub API debug') !== null){
4141
let a = path.split('/')[0];
4242
let reset = localStorage.getItem('_GitHub '+a+' x-ratelimit-reset');
@@ -63,11 +63,12 @@ class GitHubApi{
6363
if(response.status === 200){
6464
return response;
6565
}else if(response.status === 401){
66-
GitHubApi.logout();
6766
if(accessToken){
67+
GitHubApi.logout();
6868
throw new Error('Unauthorized GitHub OAuth-Token. Logged out.');
6969
}
70-
return;
70+
console.error('API call requires authorization. Call dropped.', path);
71+
return await new Promise(()=>{});
7172
}else if([403, 429/*Unconfirmed*/].includes(response.status)){
7273
let timestamp = 1000*(parseInt(response.headers.get('x-ratelimit-reset'))+1);
7374
if(this.isLoggedIn()){

0 commit comments

Comments
 (0)