Skip to content

Commit

Permalink
fix: 백준 인증 에러처리 401에만 대응하게 하기 (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoov committed Aug 6, 2024
1 parent dd05c50 commit 866e8b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions apps/baekjoon-hub/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const POOLC_BASE_URL = 'https://poolc.org/api';
const appFetch = (...args) =>
fetch(...args).then((res) => {
if (res.status === 401) {
throw new Error('unauthorized');
throw new Error('UNAUTHORIZED');
}

if (res.status >= 400) {
throw new Error('fetch error. please check network tab');
throw new Error('FETCH_ERROR');
}
return res;
});
Expand Down Expand Up @@ -35,7 +35,7 @@ function handleMessage(request, _, sendResponse) {
},
})
.then(() => sendResponse({ success: true }))
.catch(() => sendResponse({ success: false }));
.catch((e) => sendResponse({ success: false, reason: e.message }));
});
}
// login check
Expand Down
4 changes: 3 additions & 1 deletion apps/baekjoon-hub/scripts/baekjoon/baekjoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ function startLoader() {
title: psData.titles[0].title,
});
} catch (error) {
showErrorToast(`
if (error === 'UNAUTHORIZED') {
showErrorToast(`
인증이 만료되었습니다. 😭<br/>
<a href=${`chrome-extension://${chrome.runtime.id}/login.html`} style="color: #212529; font-weight: 700;">해당 링크</a>를 통해 다시 로그인해주세요. 🙏
`);
}
console.error(error);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/baekjoon-hub/scripts/baekjoon/parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async function notifyProblemSolved({ language, level, problemId, problemTags, su
if (res.success) {
resolve();
} else {
reject();
reject(res.reason);
}
},
);
Expand Down

0 comments on commit 866e8b1

Please sign in to comment.