自定义异常继承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" : "登录错了"
}

该博客介绍了如何创建一个名为`AuthException`的自定义异常类,该类继承自`OAuth2Exception`。`AuthException`包含一个错误代码字段,并重写了`getHttpErrorCode`方法以返回200作为HTTP状态码,以及`getOAuth2ErrorCode`方法用于获取自定义错误代码。当抛出`AuthException`时,返回的JSON响应包含错误代码和描述信息。
2107

被折叠的 条评论
为什么被折叠?



