|
|
@@ -42,6 +42,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import me.zhengjie.base.ResponseCodeConst;
|
|
|
import me.zhengjie.base.ResponseDTO;
|
|
|
import me.zhengjie.base.ResultCode;
|
|
|
+import me.zhengjie.exception.AccountNoActivationException;
|
|
|
import me.zhengjie.exception.BadRequestException;
|
|
|
import me.zhengjie.exception.EntityExistException;
|
|
|
import me.zhengjie.exception.EntityNotFoundException;
|
|
|
@@ -65,8 +66,8 @@ public class GlobalExceptionHandler {
|
|
|
@ResponseBody
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
public ResponseDTO<?> exceptionHandler(Exception e) {
|
|
|
- log.error("error: {}", e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("error: {} Cause {} ", e.getMessage(), e.getCause());
|
|
|
+// e.printStackTrace();
|
|
|
// http 请求方式错误
|
|
|
if (e instanceof HttpRequestMethodNotSupportedException) {
|
|
|
return ResponseDTO.error(ResultCode.REQUEST_METHOD_ERROR);
|
|
|
@@ -77,6 +78,10 @@ public class GlobalExceptionHandler {
|
|
|
return ResponseDTO.error(ResultCode.ERROR_PARAM);
|
|
|
}
|
|
|
|
|
|
+ // 账号没有激活
|
|
|
+ if (e instanceof AccountNoActivationException) {
|
|
|
+ return ResponseDTO.error(ResultCode.USER_ACCOUNT_FORBIDDEN);
|
|
|
+ }
|
|
|
// json 格式错误
|
|
|
if (e instanceof HttpMessageNotReadableException) {
|
|
|
return ResponseDTO.error(ResultCode.JSON_FORMAT_ERROR);
|
|
|
@@ -86,11 +91,15 @@ public class GlobalExceptionHandler {
|
|
|
}
|
|
|
if (e instanceof InternalAuthenticationServiceException) {
|
|
|
InternalAuthenticationServiceException error = (InternalAuthenticationServiceException) e;
|
|
|
- String message= error.getMessage();
|
|
|
- if(message.contains("UsernameNotFoundException")) {
|
|
|
+ String message = error.getMessage();
|
|
|
+ if (message != null && message.contains("UsernameNotFoundException")) {
|
|
|
return ResponseDTO.error(ResultCode.USER_LOGIN_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+ Throwable t = e.getCause();
|
|
|
+ if (t instanceof AccountNoActivationException) {
|
|
|
+ return ResponseDTO.error(ResultCode.USER_ACCOUNT_FORBIDDEN);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
// 参数校验未通过
|
|
|
if (e instanceof MethodArgumentNotValidException) {
|