Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 에러코드 detail 정보 없는 경우 수정 및 스웨거 수정 #774

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

private static final String PROPERTY_ERROR_CODE = "errorCode";
private static final String PROPERTY_TIMESTAMP = "timestamp";
private static final String DEFAULT_DETAIL_MASSAGE = "디테일 값이 존재하지 않습니다.";

@ExceptionHandler
public ResponseEntity<ProblemDetail> handleCodeZapException(CodeZapException codeZapException) {
Expand Down Expand Up @@ -63,17 +64,18 @@ public ResponseEntity<ProblemDetail> handleException(Exception exception) {
protected ResponseEntity<Object> createResponseEntity(
@Nullable Object body, HttpHeaders headers, HttpStatusCode statusCode, WebRequest request
) {
ProblemDetail problemDetail = ProblemDetail.forStatus(statusCode);
if (body instanceof Exception) {
problemDetail.setDetail(((Exception) body).getMessage());
if (body instanceof ProblemDetail) {
return ResponseEntity.status(statusCode)
.body(setProperties((ProblemDetail) body, ErrorCode.SPRING_GLOBAL_EXCEPTION.getCode()));
}
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(statusCode, DEFAULT_DETAIL_MASSAGE);
return ResponseEntity.status(statusCode)
.body(setProperties(problemDetail, ErrorCode.SPRING_GLOBAL_EXCEPTION.getCode()));
}

public static ProblemDetail setProperties(ProblemDetail problemDetail, int code) {
problemDetail.setProperty(PROPERTY_ERROR_CODE, code);
problemDetail.setProperty(PROPERTY_TIMESTAMP, LocalDateTime.now());
problemDetail.setProperty(PROPERTY_TIMESTAMP, LocalDateTime.now().toString());

return problemDetail;
}
Expand Down