青羊经侦大队-数据平台
wl
2022-07-15 1de3b3fe57cd58e76c90fb33d4cdedc67c246a58
src/main/java/com/example/jz/config/DefaultExceptionHandlerConfig.java
@@ -1,9 +1,8 @@
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.core.annotation.Order;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
@@ -17,23 +16,15 @@
@RestControllerAdvice
public class DefaultExceptionHandlerConfig {
    @ExceptionHandler(BindException.class)
    public ResponseEntity<String> bindExceptionHandler(BindException e) {
        e.printStackTrace();
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
    }
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResponseEntity<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
        e.printStackTrace();
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(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());
    }
    @ExceptionHandler(Exception.class)
    public R<String> ExceptionHandler(Exception e) {
        e.printStackTrace();
        return R.failed(e.getMessage());
    }
}