Description:
When writing business logic in the back-end, you may encounter exceptions. The back-end usually throws an exception through throw, and then annotates the custom class with the @RestControllerAdvice annotation for unified processing, and the front-end parses the received results .
Exception handling class
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
/**
* error
*/
@ExceptionHandler(BaseException.class)
public ResultVo baseException(BaseException e) {
log.error("base exception: {}", e.getMessage());
return ResultVo.error(e.getMessage());
}
}
Troubleshooting ideas
- Check whether the exception handling class is managed by Spring, @SpringbootApplication scans this package and sub-packages by default; if it is found, use @SpringbootApplication(scanBasePackages=”xxx.xxx”)
- Check the aspect programming in the project to see if an exception is try-catch in a certain aspect, and then it is not thrown out. It is common to wrap around the aspect, catching an exception and forgetting to throw it.
My question: Use the surround processing of the aspect to record the log. The log is divided into success, failure, and exception, and all exceptions are captured and processed.
Solution: After catching the exception, then throw the exception.
Read More:
- Mybatis error under Springboot project: Invalid bound statement (not found)
- [Solved] Springboot Project Startup Error: Error starting ApplicationContext
- When using postman assertion, the global variables set in the tests of the pit will take effect only after the interface is executed
- IDEA: How to Solve Springboot Project install Error
- [Solved] SpringBoot Project Start Error: No bean named ‘org.springframework.context.xxxxx.importRegistry‘ available
- [Solved] Bat starts springboot project error: ERROR org.springframework.boot.SpringApplication -Application run failed
- [Solved] Springboot project Create to start Error: APPLICATION FAILED TO START
- [Solved] Springboot Project Startup Error: Error running XXX. Command line is too long.
- [Solved] Springboot Startup Error: Consider defining a bean of type ‘XXX’ in your configuration.
- Springboot configuration project access path URL root path
- [Solved] The version of springcloud must support the current version of springboot, otherwise the startup project will report an error: error starting ApplicationContext
- [Solved] Springboot Error creating bean with name ‘dataSource’ defined in class path resource
- Error starting vue project these dependencies were not found:create in ./src/router/modules/md.js
- [Solved] Springboot WARNING: All illegal access operations will be denied in a future release
- Springboot connects to the database error: testWhileIdle is true, validationQuery not set
- [Solved] There are test failures. Please refer to D:\Java_study\springboot\springboot-sugon-3\target\surefire-reports for the individual test results.
- [Solved] SpringBoot Error: HttpMediaTypeNotSupportedException: Content type ‘application/json‘ not supported
- [Solved] volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
- Google Play googleapi: Error 403: Google Play Android Developer API has not been used in project
- [Solved] Opencv Compile Error: (CMake Error: The following variables are used in this project, but they are set to not)