throw new BadRequestException("missing required value");
public class BadRequestException extends RuntimeException {
public BadRequestException(String message) {
super(message);
}
}
@RestControllerAdvice
public class WebRestControllerAdvice {
@ExceptionHandler(BadRequestException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public SingleErrorMessage invalidParameterException(BadRequestException err) {
return new SingleErrorMessage("missing required value");
}
}
Response Status 400
{
"error": "missing required value"
}
Dev, Test, Staging, Production을 구분해보자
간단한 에러 처리 -> 고민중
spring5에 추가된 ResponseStatusException
RestControllerAdvice로 직접 ExceptionHandler하는것