Skip to content

Commit

Permalink
[#3] chore: RuntimeException 관련 파트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dl-00-e8 committed Jan 24, 2024
1 parent bf29d84 commit c573599
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public record ErrorResponse(
String message) {

public ErrorResponse(ErrorCode errorcode) {
this(LocalDateTime.now().withNano(0), errorcode.getCode(), errorcode.getMessage());
this(LocalDateTime.now(), errorcode.getCode(), errorcode.getMessage());
}

public ErrorResponse(String message) {
this(LocalDateTime.now(), ErrorCode.INTERNAL_SERVER_EXCEPTION.getCode(), message);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gongjakso.server.global.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
Expand All @@ -10,9 +11,14 @@
public class GlobalExceptionHandler {

@ExceptionHandler(ApplicationException.class)
protected ResponseEntity<ErrorResponse> handleCustomException(ApplicationException e){

protected ResponseEntity<ErrorResponse> handleApplicationException(ApplicationException e){
return ResponseEntity.status(e.getErrorCode().getHttpStatus())
.body(new ErrorResponse(e.getErrorCode()));
}

@ExceptionHandler(RuntimeException.class)
protected ResponseEntity<ErrorResponse> handleRuntimeException(RuntimeException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new ErrorResponse(e.getMessage()));
}
}

0 comments on commit c573599

Please sign in to comment.