Class OAuth2Exception

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.oauth2.exception.OAuth2Exception
All Implemented Interfaces:
Serializable

public class OAuth2Exception extends RuntimeException
OAuth2 Exception OAuth2 异常

Base exception class for all OAuth2 related errors.

所有 OAuth2 相关错误的基础异常类。

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);

Features | 主要功能:

  • OAuth2 protocol exception with error code - 带错误码的OAuth2协议异常
  • Carries error description and URI - 携带错误描述和URI

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 Details

    • OAuth2Exception

      public OAuth2Exception(OAuth2ErrorCode errorCode)
      Create exception with error code 使用错误码创建异常
      Parameters:
      errorCode - the error code | 错误码
    • OAuth2Exception

      public OAuth2Exception(OAuth2ErrorCode errorCode, String details)
      Create exception with error code and details 使用错误码和详情创建异常
      Parameters:
      errorCode - the error code | 错误码
      details - additional details | 附加详情
    • OAuth2Exception

      public OAuth2Exception(OAuth2ErrorCode errorCode, Throwable cause)
      Create exception with error code and cause 使用错误码和原因创建异常
      Parameters:
      errorCode - the error code | 错误码
      cause - the cause | 原因
    • OAuth2Exception

      public OAuth2Exception(OAuth2ErrorCode errorCode, String details, Throwable cause)
      Create exception with error code, details and cause 使用错误码、详情和原因创建异常
      Parameters:
      errorCode - the error code | 错误码
      details - additional details | 附加详情
      cause - the cause | 原因
  • Method Details

    • errorCode

      public OAuth2ErrorCode errorCode()
      Get the error code 获取错误码
      Returns:
      the error code | 错误码
    • details

      public String details()
      Get additional details 获取附加详情
      Returns:
      the details or null | 详情或 null
    • code

      public int code()
      Get the error code number 获取错误码数字
      Returns:
      the error code number | 错误码数字
    • tokenExpired

      public static OAuth2Exception tokenExpired()
      Create token expired exception 创建 Token 过期异常
      Returns:
      the exception | 异常
    • tokenInvalid

      public static OAuth2Exception tokenInvalid(String details)
      Create token invalid exception 创建 Token 无效异常
      Parameters:
      details - the details | 详情
      Returns:
      the exception | 异常
    • authorizationFailed

      public static OAuth2Exception authorizationFailed(String details)
      Create authorization failed exception 创建授权失败异常
      Parameters:
      details - the details | 详情
      Returns:
      the exception | 异常
    • networkError

      public static OAuth2Exception networkError(Throwable cause)
      Create network error exception 创建网络错误异常
      Parameters:
      cause - the cause | 原因
      Returns:
      the exception | 异常
    • invalidConfig

      public static OAuth2Exception invalidConfig(String details)
      Create invalid config exception 创建无效配置异常
      Parameters:
      details - the details | 详情
      Returns:
      the exception | 异常