mirror of https://gitee.com/maxjhandsome/pig
fixed: 异常处理bug
This commit is contained in:
parent
742a162f98
commit
d071985eca
|
@ -5,6 +5,7 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
||||
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
|
||||
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
|
||||
import org.springframework.security.oauth2.common.exceptions.UnsupportedResponseTypeException;
|
||||
import org.springframework.security.oauth2.provider.error.DefaultWebResponseExceptionTranslator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -25,6 +26,8 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
public class PigWebResponseExceptionTranslator extends DefaultWebResponseExceptionTranslator {
|
||||
|
||||
public static final String BAD_MSG = "坏的凭证";
|
||||
|
||||
/**
|
||||
* @param e spring security内部异常
|
||||
* @return 经过处理的异常信息
|
||||
|
@ -33,12 +36,12 @@ public class PigWebResponseExceptionTranslator extends DefaultWebResponseExcepti
|
|||
@Override
|
||||
public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception {
|
||||
OAuth2Exception oAuth2Exception;
|
||||
if (e instanceof InvalidGrantException && StringUtils.equals("坏的凭证",e.getMessage())) {
|
||||
if (e instanceof InvalidGrantException && StringUtils.equals(BAD_MSG, e.getMessage())) {
|
||||
oAuth2Exception = new InvalidGrantException("密码错误", e);
|
||||
} else if (e instanceof InternalAuthenticationServiceException) {
|
||||
oAuth2Exception = new InvalidGrantException("用户名不存在", e);
|
||||
} else {
|
||||
oAuth2Exception = (OAuth2Exception) e;
|
||||
oAuth2Exception = new UnsupportedResponseTypeException("服务处理异常", e);
|
||||
}
|
||||
return super.translate(oAuth2Exception);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue