自定义异常继承OAuth2Exception
public class AuthException extends OAuth2Exception { private String code; public AuthException (String code, String msg) { super(msg); this.code=code; } @Override public int getHttpErrorCode() { return 200; } @Override public String getOAuth2ErrorCode() { return code; } }
说明:
getHttpErrorCode()方法返回状态需在org.springframework.http.HttpStatus中存在
使用:
throw new AuthException("ssCode","登录错了");
返回:
{
"error" : "ssCode",
"error_description" : "登录错了"
}