Skip to content

Commit

Permalink
[#6] feat: Create GlobalExceptionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac56 committed May 7, 2021
1 parent 6b039c8 commit c730f23
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit c730f23

Please sign in to comment.