|
@@ -6,6 +6,8 @@ import exception.TooManyDeviceException;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
|
|
+import org.springframework.security.authentication.BadCredentialsException;
|
|
|
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
import org.springframework.validation.FieldError;
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
@@ -20,6 +22,9 @@ import javax.validation.ConstraintViolationException;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static cn.kdan.pdf.backend.core.constant.AuthConstant.EXCEPTION_CODE_USER_NOT_FOUND;
|
|
|
+import static cn.kdan.pdf.backend.core.constant.AuthConstant.EXCEPTION_CODE_USER_PASSWORD_ERROR;
|
|
|
+
|
|
|
/**
|
|
|
* @author tangxiangan
|
|
|
*/
|
|
@@ -71,4 +76,18 @@ public class ControllerExceptionHandler {
|
|
|
return new ResultMap<>(CommonConstant.EXCEPTION_CODE_SERVER_ERROR, "参数错误: " + e.getParameterName() + " 缺失");
|
|
|
}
|
|
|
|
|
|
+ @ExceptionHandler(UsernameNotFoundException.class)
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMap<?> handlerUsernameNotFoundException(UsernameNotFoundException e) {
|
|
|
+ logger.info(e.getMessage(), e);
|
|
|
+ return new ResultMap<>(EXCEPTION_CODE_USER_NOT_FOUND, "错误信息: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ @ExceptionHandler(BadCredentialsException.class)
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMap<?> handlerBadCredentialsException(BadCredentialsException e) {
|
|
|
+ logger.info(e.getMessage(), e);
|
|
|
+ return new ResultMap<>(EXCEPTION_CODE_USER_PASSWORD_ERROR, "错误信息: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
}
|