Skip to content

Commit

Permalink
[chore] #151 OPEN API 응답 파싱이 불가한 경우에 대한 예외처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
chanwoo7 committed Sep 18, 2024
1 parent cdf31f8 commit 14ade58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ private URL setRequest(String subUrl, OpenAPIRequestInterface dto) throws Except
private JSONObject readStreamToJson(InputStreamReader streamResponse, OpenAPIResponseInterface responseDto) throws Exception {
log.trace("OpenAPI > readStreamToJson()");
String fullResponse = new BufferedReader(streamResponse).readLine();
JSONObject jsonObject;

// response JSON 파싱
JSONObject jsonObject = (JSONObject) (new JSONParser()).parse(fullResponse);
try {
jsonObject = (JSONObject) (new JSONParser()).parse(fullResponse);
} catch (Exception e) {
throw new CustomException(ErrorCode.INVALID_OPENAPI_RESPONSE);
}

JSONObject response = (JSONObject) jsonObject.get("response");

// API 일일 호출 횟수 초과 에러 (일 최대 500건)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/book/backend/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public enum ErrorCode {

// 외부 API 에러
KAKAO_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "500", "카카오 서버에 오류가 발생했습니다."),
INVALID_OPENAPI_RESPONSE(HttpStatus.INTERNAL_SERVER_ERROR, "500", "OPEN API 서버에서 잘못된 응답을 전송했습니다."),
API_CALL_LIMIT_EXCEEDED(HttpStatus.TOO_MANY_REQUESTS, "429", "OPEN API 일일 호출 횟수를 초과했습니다. (일 최대 500건)"),
LIBCODE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "500", "존재하는 도서관 코드인지 확인해주세요."),
OPENAPI_REQUEST_TIMEOUT(HttpStatus.REQUEST_TIMEOUT, "408", "OPEN API 응답을 요청하는 중 타임아웃이 발생했습니다."),
Expand Down

0 comments on commit 14ade58

Please sign in to comment.