forked from woowacourse/javascript-movie-review
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 통신에 실패할 경우 오류를 발생시키고, 해당 오류가 발생한 경우 오류 메세지를 띄워주는 기능 구현
Co-authored-by: cys4585 <[email protected]>
- Loading branch information
Showing
10 changed files
with
163 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const validateResponse = (status: number) => { | ||
if (status === 401) { | ||
throw new Error("인증 정보가 올바르지 않습니다. API KEY를 확인해주세요."); | ||
} | ||
if (status === 503) { | ||
throw new Error( | ||
"죄송합니다. 현재 서버가 일시적으로 오프라인 상태입니다. 나중에 다시 시도해주세요." | ||
); | ||
} | ||
if (500 <= status) { | ||
throw new Error( | ||
"죄송합니다. 서버가 점검중입니다. 다음에 다시 시도해주세요." | ||
); | ||
} | ||
if (400 <= status) { | ||
throw new Error("알 수 없는 오류가 발생했습니다. 다시 시도해주세요."); | ||
} | ||
}; | ||
|
||
export default validateResponse; | ||
|
||
// TMDB 에서 올 수 있는 모든 ERROR 목록 | ||
// 400: "사용자 이름과 비밀번호를 제공해야 합니다. 잘못된 페이지, 날짜형식입니다. validation failed. 검증실패.", | ||
// 401: "API Key가 없습니다. API Key가 일시 정지됐습니다.", | ||
// 403: "이 사용자는 정지되었습니다. 제출하려는 데이터가 이미 존재합니다.", | ||
// 404: "잘못된 아이디거나 찾을 수 없습니다. ", | ||
// 405: "이 서비스는 그 형식이 아닙니다. 잘못된 형식. 해당 형식이 존재하지 않습니다.", | ||
// 406: "잘못 승인된 헤더입니다.", | ||
// 422: "잘못된 날짜 범위(14일 이하여야 합니다). invalid parameter. 요청의 파라미터가 올바르지 않습니다.", | ||
// 429: "요청 횟수가 허용 한도(40회)를 초과했습니다.", | ||
// 500: "default server error. 내부 오류. 문제 발생. TMDB에 문의해주세요.", | ||
// 501: "서버가 존재하지 않습니다.", | ||
// 502: "백엔드 서버에 연결할 수 없습니다.", | ||
// 503: "이 API가 점검 중입니다. 이 서비스는 일시적으로 오프라인 상태입니다. 나중에 다시 시도하세요.", | ||
// 504: "백엔드 서버에 대한 요청 시간 초과. 다시 시도하세요.", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters