Home > Back-end >  RestControllerAdvice effect
RestControllerAdvice effect

Time:11-13

Use RestControllerAdvice do global abnormal control, return to one of my custom objects,
Use the debug mode step by step, there is an Error to normal into the class of the RestControllerAdvice annotation corresponding ExceptionHandler annotation methods, also returned to my custom objects, but in the final return results, is not my custom this object, but the default Error for springmvc, Internal Server Error,
The answer to the Internet, get basic is wrong not normal to throw, the tangent plane of limit ah of what, but definitely normal throws errors, or not to enter the abnormal control of plane is just some authentication ah of what, I also tried dropped the aop are disabled, but still won't do,

CodePudding user response:


/* ** @ author liuyh 
* @ Description:
* @ date 2020/9/22 14:13
*/
@ ControllerAdvice
@ Slf4j
Public class ExceptionError {
@ ExceptionHandler (value=https://bbs.csdn.net/topics/Exception.class)
@ ResponseBody
Public Result defaultErrorHandler (it the req, HttpServletResponse resp, Exception e) {
e.printStackTrace();
The Result resul=new Result ();
If (e instanceof HttpRequestMethodNotSupportedException) {
Resul. SetResltInfo (Constant CODE_TYPE_10, "illegal request," um participant etMessage ());
{} else if (e instanceof HystrixRuntimeException)
Resul. SetResltInfo (Constant CODE_TYPE_30, "feign call system abnormalities," um participant etCause (). The getMessage ());
} else {
Resul. SetResltInfo (Constant CODE_TYPE_1, "a system exception", um participant etMessage ());
}
Return resul.
}
}
  • Related