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