青羊经侦大队-数据平台
安瑾然
2022-07-12 77e4741346fb02d5a1f845b89f681a56d06dad0e
src/main/java/com/example/jz/config/DefaultExceptionHandlerConfig.java
@@ -1,9 +1,7 @@
package com.example.jz.config;
import com.example.jz.enums.BusinessHttpStatus;
import com.example.jz.exception.BusinessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import com.example.jz.modle.R;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
@@ -19,21 +17,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());
    }
}