public abstract class AbstractWebExceptionHandler extends Object
`@ControllerAdvice
public class WebExceptionHandler extends AbstractWebExceptionHandler {}
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
BAD_REQUEST |
protected static org.slf4j.Logger |
LOGGER |
static int |
NOT_ALLOWED |
static int |
SERVER_ERROR |
static int |
UNAUTHORIZED |
static int |
UNSUPPORT_MEDIA |
| 构造器和说明 |
|---|
AbstractWebExceptionHandler() |
AbstractWebExceptionHandler(String unauthorizedPage,
String serverErrorPage,
String defaultErrorMsg) |
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
handErrorPage(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String page) |
void |
handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
BaseUncheckedException e)
500 - Biz operate failure
|
void |
handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
org.springframework.validation.BindException e)
400 - Bind error: jsr 303
Controller方法中无BindingResult参数
public Result testValidate1(@Valid Article article) {}
注:
1、@org.springframework.validation.annotation.Validated可代替@Valid
2、类型转换失败(如前端传错误的日期格式)也会抛BindException
|
void |
handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
javax.validation.ConstraintViolationException e)
400 - Constraint violation: jsr 303
1、加配置:
|
void |
handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
Exception e)
400 - Bad Request
|
void |
handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
org.springframework.web.HttpMediaTypeNotSupportedException e)
415 - Unsupported Media Type
|
void |
handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
org.springframework.web.HttpRequestMethodNotSupportedException e)
405 - Method Not Allowed
|
protected void |
handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String page,
int code,
String message) |
void |
handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
Throwable t)
500 - Internal Server Error
|
void |
handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
UnauthorizedException e)
401 - Unauthorized
|
void |
handleMethod(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
org.springframework.web.bind.MethodArgumentNotValidException e)
400 - Method argument not valid: jsr 303
含@RequestBody注解(HttpMessageConverter application/json)
Controller方法中无BindingResult参数
public Result testValidate2(@RequestBody `@Valid Article article) {}
注:
1、@org.springframework.validation.annotation.Validated可代替@Valid
2、类型转换失败(如前端传错误的日期格式)会抛HttpMessageNotReadableException,不会抛MethodArgumentNotValidException(即不会进入此方法)
|
public static final int UNAUTHORIZED
public static final int BAD_REQUEST
public static final int NOT_ALLOWED
public static final int UNSUPPORT_MEDIA
public static final int SERVER_ERROR
protected static final org.slf4j.Logger LOGGER
@ExceptionHandler(value=UnauthorizedException.class) public void handle(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, UnauthorizedException e)
@ExceptionHandler(value=org.springframework.validation.BindException.class)
public void handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
org.springframework.validation.BindException e)
@ExceptionHandler(value=org.springframework.web.bind.MethodArgumentNotValidException.class)
public void handleMethod(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
org.springframework.web.bind.MethodArgumentNotValidException e)
@ExceptionHandler(value=javax.validation.ConstraintViolationException.class)
public void handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
javax.validation.ConstraintViolationException e)
@ExceptionHandler(value={java.lang.IllegalArgumentException.class,java.lang.IllegalStateException.class,org.springframework.beans.TypeMismatchException.class,org.springframework.http.converter.HttpMessageNotReadableException.class,org.springframework.web.bind.ServletRequestBindingException.class})
public void handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
Exception e)
@ExceptionHandler(value=org.springframework.web.HttpRequestMethodNotSupportedException.class)
public void handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
org.springframework.web.HttpRequestMethodNotSupportedException e)
@ExceptionHandler(value=org.springframework.web.HttpMediaTypeNotSupportedException.class)
public void handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
org.springframework.web.HttpMediaTypeNotSupportedException e)
@ExceptionHandler(value=BaseUncheckedException.class) public void handle(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, BaseUncheckedException e)
@ExceptionHandler(value=java.lang.Throwable.class) public void handle(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, Throwable t)
protected void handle(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String page,
int code,
String message)
protected void handErrorPage(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String page)
Copyright © 2023. All rights reserved.