With the @controlleradvice annotation, @exceptionhandler can specify the subdivision type of the exception on the specified controller
@ControllerAdvice
public class BaseController {
private static final Logger logger = LoggerFactory.getLogger(BaseController.class);
/**
* Parameter type conversion error
*
* @param exception error
* @return error message
*/
@ExceptionHandler(HttpMessageConversionException.class)
public String parameterTypeException(HttpMessageConversionException exception){
logger.error(exception.getCause().getLocalizedMessage());
return ResultErr("Type conversion error");
}
/**
* Uniform exception handling
*/
@ExceptionHandler(value = Exception.class)
@ResponseBody
public String handlerException(Exception e) {
logger.error("Data check failure : errorMessage{"+e.getMessage()+"}");
return ResultErr(e.getCode(), e.getMessage());
}
}
Read More:
- [Solved] openstack4j Startup Error: java.net.UnknownHostException: controller
- JDK installation exception link it with ‘- Z noexecstack’ and inux 64 bit zendguardloader.so: wrong elf class: elfclass32 error handling
- [Solved] Hbase-shell 2.x Error: Unhandled Java exception: java.lang.IncompatibleClassChangeError: Found class jline.Terminal…
- Java uses class array to report error Exception in thread “main” java.lang.NullPointerException solution
- Java learning unreported exception java.io.IOException ; must be caught or declared to be thrown
- nested exception is java.lang.StackOverflowError [How to Solve]
- [Solved] Method threw ‘java.lang.StackOverflowError‘ exception. Cannot evaluate
- I/O error while reading input message; nested exception is java.io.IOException: Stream closed
- Request processing failed; nested exception is java.lang.NullPointerException or UnsatisfiedDependencyE
- [Solved] Java.lang.BootstrapMethodError: call site initialization exception
- How to Solve Swagger Always Displays “basic-error-controller” Issue
- The controller error: the XX method in the service cannot be found
- [Solved] qrcode-error: Exception in thread “main” java.lang.NoClassDefFoundError…
- [Solved] nacos Startup Error: nested exception is java.lang.RuntimeException: java.lang.RuntimeException: [db-load-error
- JAVA Code Start Exception Error View Does Not Exsit [Solved]
- [Solved] hadoop Error: 9000 failed on connection exception java.net.ConnectException Denied to Access
- [Solved] Exception in thread “main“ java.lang.NoSuchFieldError: level
- [Solved] Invocation of init method failed; nested exception is java.lang.NoSuchMethodError:
- [Solved] nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
- [Solved] Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException