import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
@Slf4j
@RestControllerAdvice
public class RestExceptionAdvice {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler({MethodArgumentTypeMismatchException.class, IllegalArgumentException.class})
public ErrorResult illegalArgumentExceptionHandle(Exception e) {
log.error("[exception] ", e);
return new ErrorResult("값을 제대로 입력하여 주세요.", HttpStatus.BAD_REQUEST.toString());
}
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler
public ErrorResult notFoundSuchFileExceptionHandler(NotFoundSuchDataException e) {
log.error("[exception] ", e);
return new ErrorResult("요청한 값을 찾을 수 없습니다.", HttpStatus.BAD_REQUEST.toString());
}
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler
public ErrorResult exHandle(Exception e) {
log.error("[exception] ", e);
return new ErrorResult("서버 내부에 문제가 발생하였습니다.", HttpStatus.INTERNAL_SERVER_ERROR.toString());
}
}