增加异常处理
This commit is contained in:
@@ -5,10 +5,12 @@ import cn.dev33.satoken.exception.NotPermissionException;
|
|||||||
import cn.hutool.core.exceptions.ValidateException;
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
import com.czg.resp.CzgRespCode;
|
import com.czg.resp.CzgRespCode;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
|
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||||
import org.springframework.validation.ObjectError;
|
import org.springframework.validation.ObjectError;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
@@ -30,6 +32,7 @@ public class CzgControllerAdvice {
|
|||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public CzgResult<Object> errorHandler(Exception ex) {
|
public CzgResult<Object> errorHandler(Exception ex) {
|
||||||
setErrorLog(ex);
|
setErrorLog(ex);
|
||||||
|
log.error("", ex);
|
||||||
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR);
|
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +44,14 @@ public class CzgControllerAdvice {
|
|||||||
return CzgResult.failure(CzgRespCode.NOT_LOGIN);
|
return CzgResult.failure(CzgRespCode.NOT_LOGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@ExceptionHandler(value = HttpMessageNotReadableException.class)
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
public CzgResult<Object> invalidFormatExceptionErrorHandler(HttpMessageNotReadableException ex) {
|
||||||
|
setErrorLog(ex);
|
||||||
|
return CzgResult.failure(ex.getRootCause() == null ? ex.getMessage() : ex.getRootCause().getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler(value = NotPermissionException.class)
|
@ExceptionHandler(value = NotPermissionException.class)
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
|||||||
Reference in New Issue
Block a user