Class OpenWebException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.web.exception.OpenWebException
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
OpenBizException, OpenCryptoException

public class OpenWebException extends RuntimeException
Open Web Exception Web异常

Base exception for web layer errors.

Web层错误的基础异常。

Features | 主要功能:

  • Error code and HTTP status support - 错误码和 HTTP 状态码支持
  • ResultCode integration - ResultCode 集成
  • Factory methods for common HTTP errors - 常见 HTTP 错误的工厂方法
  • Cause chain support - 异常链支持

Usage Examples | 使用示例:

// Using factory methods
throw OpenWebException.badRequest("Invalid parameter");
throw OpenWebException.notFound("User not found");
throw OpenWebException.unauthorized("Token expired");

// Using ResultCode
throw new OpenWebException(CommonResultCode.FORBIDDEN);

Security | 安全性:

  • Thread-safe: Yes (immutable fields) - 线程安全: 是(不可变字段)
  • Null-safe: No (message should not be null) - 空值安全: 否(消息不应为 null)
Since:
JDK 25, opencode-base-web V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenWebException

      public OpenWebException(String message)
      Create exception with message 使用消息创建异常
      Parameters:
      message - the message | 消息
    • OpenWebException

      public OpenWebException(String code, String message)
      Create exception with code and message 使用代码和消息创建异常
      Parameters:
      code - the code | 代码
      message - the message | 消息
    • OpenWebException

      public OpenWebException(String code, String message, int httpStatus)
      Create exception with code, message and HTTP status 使用代码、消息和HTTP状态创建异常
      Parameters:
      code - the code | 代码
      message - the message | 消息
      httpStatus - the HTTP status | HTTP状态
    • OpenWebException

      public OpenWebException(ResultCode resultCode)
      Create exception with result code 使用响应码创建异常
      Parameters:
      resultCode - the result code | 响应码
    • OpenWebException

      public OpenWebException(ResultCode resultCode, String message)
      Create exception with result code and custom message 使用响应码和自定义消息创建异常
      Parameters:
      resultCode - the result code | 响应码
      message - the custom message | 自定义消息
    • OpenWebException

      public OpenWebException(String message, Throwable cause)
      Create exception with message and cause 使用消息和原因创建异常
      Parameters:
      message - the message | 消息
      cause - the cause | 原因
    • OpenWebException

      public OpenWebException(ResultCode resultCode, Throwable cause)
      Create exception with result code and cause 使用响应码和原因创建异常
      Parameters:
      resultCode - the result code | 响应码
      cause - the cause | 原因
  • Method Details

    • getCode

      public String getCode()
      Get the code 获取代码
      Returns:
      the code | 代码
    • getHttpStatus

      public int getHttpStatus()
      Get the HTTP status 获取HTTP状态
      Returns:
      the HTTP status | HTTP状态
    • badRequest

      public static OpenWebException badRequest(String message)
      Create bad request exception 创建请求错误异常
      Parameters:
      message - the message | 消息
      Returns:
      the exception | 异常
    • unauthorized

      public static OpenWebException unauthorized(String message)
      Create unauthorized exception 创建未授权异常
      Parameters:
      message - the message | 消息
      Returns:
      the exception | 异常
    • forbidden

      public static OpenWebException forbidden(String message)
      Create forbidden exception 创建禁止访问异常
      Parameters:
      message - the message | 消息
      Returns:
      the exception | 异常
    • notFound

      public static OpenWebException notFound(String message)
      Create not found exception 创建资源不存在异常
      Parameters:
      message - the message | 消息
      Returns:
      the exception | 异常
    • internalError

      public static OpenWebException internalError(String message)
      Create internal error exception 创建内部错误异常
      Parameters:
      message - the message | 消息
      Returns:
      the exception | 异常
    • internalError

      public static OpenWebException internalError(String message, Throwable cause)
      Create internal error exception with cause 创建带原因的内部错误异常
      Parameters:
      message - the message | 消息
      cause - the cause | 原因
      Returns:
      the exception | 异常