diff --git a/BE/baseball/src/main/java/team9/baseball/exceptionHandler/GlobalExceptionHandler.java b/BE/baseball/src/main/java/team9/baseball/exceptionHandler/GlobalExceptionHandler.java new file mode 100644 index 000000000..28a23aad0 --- /dev/null +++ b/BE/baseball/src/main/java/team9/baseball/exceptionHandler/GlobalExceptionHandler.java @@ -0,0 +1,23 @@ +package team9.baseball.exceptionHandler; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import team9.baseball.DTO.response.ApiResult; +import team9.baseball.exception.NotFoundException; + +@RestControllerAdvice +public class GlobalExceptionHandler { + @ExceptionHandler(RuntimeException.class) + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public ApiResult runtimeExcpetion(Exception ex) { + return ApiResult.failed(ex); + } + + @ExceptionHandler(NotFoundException.class) + @ResponseStatus(HttpStatus.NOT_FOUND) + public ApiResult notFoundException(Exception ex) { + return ApiResult.failed(ex); + } +}