mirror of
https://github.com/RemainderTime/spring-boot-base-demo.git
synced 2026-06-10 03:57:41 +08:00
新增其他异常捕获处理器
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package cn.xf.basedemo.common.exception;
|
package cn.xf.basedemo.common.exception;
|
||||||
|
|
||||||
|
import cn.xf.basedemo.common.enums.SystemStatus;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@@ -83,4 +84,18 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler{
|
|||||||
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
|
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