青羊经侦大队-数据平台
安瑾然
2022-07-12 da52a1ba7e8fc2d8e633655484e7ff4abed319c8
src/main/java/com/example/jz/config/DefaultExceptionHandlerConfig.java
@@ -2,6 +2,7 @@
import com.example.jz.enums.BusinessHttpStatus;
import com.example.jz.exception.BusinessException;
import com.example.jz.modle.entity.R;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
@@ -19,21 +20,21 @@
    @ExceptionHandler(BindException.class)
    public ResponseEntity<String> bindExceptionHandler(BindException e) {
    public R<String> bindExceptionHandler(BindException e) {
        e.printStackTrace();
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
        return R.failed(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
    }
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResponseEntity<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
    public R<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
        e.printStackTrace();
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
        return R.failed(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
    }
    @ExceptionHandler(BusinessException.class)
    public ResponseEntity<String> unauthorizedExceptionHandler(BusinessException e) {
    public R<String> unauthorizedExceptionHandler(BusinessException e) {
        e.printStackTrace();
        return ResponseEntity.status(e.getHttpStatusCode()).body(e.getMessage());
        return R.failed(e.getMessage());
    }
}