mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 05:00:25 +08:00
fix(OAuthExceptionHandler.class):认证异常添加http状态码
This commit is contained in:
parent
6124eaeb04
commit
270babffbc
@ -3,11 +3,13 @@ package com.youlai.auth.common.exception;
|
||||
import com.youlai.common.result.Result;
|
||||
import com.youlai.common.result.ResultCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
|
||||
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
@ -20,6 +22,7 @@ public class OAuthExceptionHandler {
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(UsernameNotFoundException.class)
|
||||
public Result handleUsernameNotFoundException(UsernameNotFoundException e) {
|
||||
return Result.failed(ResultCode.USER_NOT_EXIST);
|
||||
@ -31,9 +34,10 @@ public class OAuthExceptionHandler {
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(InvalidGrantException.class)
|
||||
public Result handleInvalidGrantException(InvalidGrantException e) {
|
||||
return Result.failed(ResultCode.USERNAME_OR_PASSWORD_ERROR);
|
||||
return Result.failed(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@ -43,6 +47,7 @@ public class OAuthExceptionHandler {
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler({InternalAuthenticationServiceException.class})
|
||||
public Result handleInternalAuthenticationServiceException(InternalAuthenticationServiceException e) {
|
||||
return Result.failed(e.getMessage());
|
||||
@ -54,6 +59,7 @@ public class OAuthExceptionHandler {
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler({InvalidTokenException.class})
|
||||
public Result handleInvalidTokenExceptionException(InvalidTokenException e) {
|
||||
return Result.failed(e.getMessage());
|
||||
|
Loading…
Reference in New Issue
Block a user