Class OAuth2Exception
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.oauth2.exception.OAuth2Exception
- All Implemented Interfaces:
Serializable
OAuth2 Exception
OAuth2 异常
Base exception class for all OAuth2 related errors, extending OpenException
for unified error handling across OpenCode components.
所有 OAuth2 相关错误的基础异常类,继承 OpenException 以实现 OpenCode 组件的统一错误处理。
Features | 主要功能:
- Extends OpenException for unified error hierarchy - 继承 OpenException 实现统一异常层次
- OAuth2 protocol exception with error code - 带错误码的 OAuth2 协议异常
- Carries error description and URI - 携带错误描述和 URI
- RFC 6749 server error response parsing - RFC 6749 服务器错误响应解析
- Formatted message output [OAuth2] (Code) Message - 格式化消息输出
Usage Examples | 使用示例:
// Throw with error code
throw new OAuth2Exception(OAuth2ErrorCode.TOKEN_EXPIRED);
// Throw with error code and details
throw new OAuth2Exception(OAuth2ErrorCode.AUTHORIZATION_FAILED, "Invalid code");
// Throw with error code and cause
throw new OAuth2Exception(OAuth2ErrorCode.NETWORK_ERROR, e);
// Create from server error response (RFC 6749)
throw OAuth2Exception.fromServerError("invalid_grant", "The authorization code has expired", "https://example.com/errors/expired");
Security | 安全性:
- Thread-safe: Yes (immutable exception) - 线程安全: 是(不可变异常)
- Null-safe: Yes (validates inputs) - 空值安全: 是(验证输入)
- Since:
- JDK 25, opencode-base-oauth2 V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionOAuth2Exception(OAuth2ErrorCode errorCode) Create exception with error code 使用错误码创建异常OAuth2Exception(OAuth2ErrorCode errorCode, String details) Create exception with error code and details 使用错误码和详情创建异常OAuth2Exception(OAuth2ErrorCode errorCode, String details, String serverError, String serverErrorDescription, String serverErrorUri) Create exception with error code and server error fields (RFC 6749) 使用错误码和服务器错误字段创建异常(RFC 6749)OAuth2Exception(OAuth2ErrorCode errorCode, String details, Throwable cause) Create exception with error code, details and cause 使用错误码、详情和原因创建异常OAuth2Exception(OAuth2ErrorCode errorCode, Throwable cause) Create exception with error code and cause 使用错误码和原因创建异常 -
Method Summary
Modifier and TypeMethodDescriptionstatic OAuth2ExceptionauthorizationFailed(String details) Create authorization failed exception 创建授权失败异常intcode()Get the error code number 获取错误码数字details()Get additional details 获取附加详情Get the error code 获取错误码static OAuth2ExceptionfromServerError(String error, String errorDescription, String errorUri) Create exception from an OAuth2 server error response (RFC 6749 Section 5.2) 从 OAuth2 服务器错误响应创建异常(RFC 6749 第 5.2 节)Get the formatted exception message, including server error details when present.static OAuth2ExceptioninvalidConfig(String details) Create invalid config exception 创建无效配置异常static OAuth2ExceptionnetworkError(Throwable cause) Create network error exception 创建网络错误异常Get the server error string from the OAuth2 error response (RFC 6749) 获取 OAuth2 错误响应中的服务器错误字符串(RFC 6749)Get the server error description from the OAuth2 error response (RFC 6749) 获取 OAuth2 错误响应中的服务器错误描述(RFC 6749)Get the server error URI from the OAuth2 error response (RFC 6749) 获取 OAuth2 错误响应中的服务器错误 URI(RFC 6749)static OAuth2ExceptionCreate token expired exception 创建 Token 过期异常static OAuth2ExceptiontokenInvalid(String details) Create token invalid exception 创建 Token 无效异常Methods inherited from class OpenException
getComponent, getErrorCode, getRawMessageMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
OAuth2Exception
Create exception with error code 使用错误码创建异常- Parameters:
errorCode- the error code | 错误码
-
OAuth2Exception
Create exception with error code and details 使用错误码和详情创建异常- Parameters:
errorCode- the error code | 错误码details- additional details | 附加详情
-
OAuth2Exception
Create exception with error code and cause 使用错误码和原因创建异常- Parameters:
errorCode- the error code | 错误码cause- the cause | 原因
-
OAuth2Exception
Create exception with error code, details and cause 使用错误码、详情和原因创建异常- Parameters:
errorCode- the error code | 错误码details- additional details | 附加详情cause- the cause | 原因
-
OAuth2Exception
public OAuth2Exception(OAuth2ErrorCode errorCode, String details, String serverError, String serverErrorDescription, String serverErrorUri) Create exception with error code and server error fields (RFC 6749) 使用错误码和服务器错误字段创建异常(RFC 6749)- Parameters:
errorCode- the error code | 错误码details- additional details | 附加详情serverError- the OAuth2 server error string | OAuth2 服务器错误字符串serverErrorDescription- the server error description | 服务器错误描述serverErrorUri- the server error URI | 服务器错误 URI
-
-
Method Details
-
errorCode
-
details
-
code
public int code()Get the error code number 获取错误码数字- Returns:
- the error code number | 错误码数字
-
serverError
Get the server error string from the OAuth2 error response (RFC 6749) 获取 OAuth2 错误响应中的服务器错误字符串(RFC 6749)- Returns:
- the server error string or null | 服务器错误字符串或 null
-
serverErrorDescription
Get the server error description from the OAuth2 error response (RFC 6749) 获取 OAuth2 错误响应中的服务器错误描述(RFC 6749)- Returns:
- the server error description or null | 服务器错误描述或 null
-
serverErrorUri
Get the server error URI from the OAuth2 error response (RFC 6749) 获取 OAuth2 错误响应中的服务器错误 URI(RFC 6749)- Returns:
- the server error URI or null | 服务器错误 URI 或 null
-
getMessage
Get the formatted exception message, including server error details when present. 获取格式化的异常消息,当存在时包含服务器错误详情。- Overrides:
getMessagein classOpenException- Returns:
- the formatted message | 格式化的消息
-
tokenExpired
Create token expired exception 创建 Token 过期异常- Returns:
- the exception | 异常
-
tokenInvalid
Create token invalid exception 创建 Token 无效异常- Parameters:
details- the details | 详情- Returns:
- the exception | 异常
-
authorizationFailed
Create authorization failed exception 创建授权失败异常- Parameters:
details- the details | 详情- Returns:
- the exception | 异常
-
networkError
Create network error exception 创建网络错误异常- Parameters:
cause- the cause | 原因- Returns:
- the exception | 异常
-
invalidConfig
Create invalid config exception 创建无效配置异常- Parameters:
details- the details | 详情- Returns:
- the exception | 异常
-
fromServerError
public static OAuth2Exception fromServerError(String error, String errorDescription, String errorUri) Create exception from an OAuth2 server error response (RFC 6749 Section 5.2) 从 OAuth2 服务器错误响应创建异常(RFC 6749 第 5.2 节)- Parameters:
error- the error code string from server | 服务器返回的错误码字符串errorDescription- the error description from server | 服务器返回的错误描述errorUri- the error URI from server | 服务器返回的错误 URI- Returns:
- the exception | 异常
-