mirror of
https://github.com/RemainderTime/spring-boot-base-demo.git
synced 2026-02-22 22:21:05 +08:00
新增其他异常捕获处理器
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.xf.basedemo.common.exception;
|
||||
|
||||
import cn.xf.basedemo.common.enums.SystemStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -83,4 +84,18 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler{
|
||||
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* 其他异常捕获
|
||||
* @param request
|
||||
* @param e
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity exceptionHandler(jakarta.servlet.http.HttpServletRequest request, final Exception e, jakarta.servlet.http.HttpServletResponse response) {
|
||||
Map<String, String> errors = new HashMap<>();
|
||||
errors.put("message", e.getMessage());
|
||||
return ResponseEntity.status(SystemStatus.ERROR.getCode()).body(errors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user