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
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 Summary
ConstructorsConstructorDescriptionOpenWebException(ResultCode resultCode) Create exception with result code 使用响应码创建异常OpenWebException(ResultCode resultCode, String message) Create exception with result code and custom message 使用响应码和自定义消息创建异常OpenWebException(ResultCode resultCode, Throwable cause) Create exception with result code and cause 使用响应码和原因创建异常OpenWebException(String message) Create exception with message 使用消息创建异常OpenWebException(String code, String message) Create exception with code and message 使用代码和消息创建异常OpenWebException(String code, String message, int httpStatus) Create exception with code, message and HTTP status 使用代码、消息和HTTP状态创建异常OpenWebException(String message, Throwable cause) Create exception with message and cause 使用消息和原因创建异常 -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenWebExceptionbadRequest(String message) Create bad request exception 创建请求错误异常static OpenWebExceptionCreate forbidden exception 创建禁止访问异常getCode()Get the code 获取代码intGet the HTTP status 获取HTTP状态static OpenWebExceptioninternalError(String message) Create internal error exception 创建内部错误异常static OpenWebExceptioninternalError(String message, Throwable cause) Create internal error exception with cause 创建带原因的内部错误异常static OpenWebExceptionCreate not found exception 创建资源不存在异常static OpenWebExceptionunauthorized(String message) Create unauthorized exception 创建未授权异常Methods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
OpenWebException
Create exception with message 使用消息创建异常- Parameters:
message- the message | 消息
-
OpenWebException
-
OpenWebException
-
OpenWebException
Create exception with result code 使用响应码创建异常- Parameters:
resultCode- the result code | 响应码
-
OpenWebException
Create exception with result code and custom message 使用响应码和自定义消息创建异常- Parameters:
resultCode- the result code | 响应码message- the custom message | 自定义消息
-
OpenWebException
-
OpenWebException
Create exception with result code and cause 使用响应码和原因创建异常- Parameters:
resultCode- the result code | 响应码cause- the cause | 原因
-
-
Method Details
-
getCode
-
getHttpStatus
public int getHttpStatus()Get the HTTP status 获取HTTP状态- Returns:
- the HTTP status | HTTP状态
-
badRequest
Create bad request exception 创建请求错误异常- Parameters:
message- the message | 消息- Returns:
- the exception | 异常
-
unauthorized
Create unauthorized exception 创建未授权异常- Parameters:
message- the message | 消息- Returns:
- the exception | 异常
-
forbidden
Create forbidden exception 创建禁止访问异常- Parameters:
message- the message | 消息- Returns:
- the exception | 异常
-
notFound
Create not found exception 创建资源不存在异常- Parameters:
message- the message | 消息- Returns:
- the exception | 异常
-
internalError
Create internal error exception 创建内部错误异常- Parameters:
message- the message | 消息- Returns:
- the exception | 异常
-
internalError
Create internal error exception with cause 创建带原因的内部错误异常- Parameters:
message- the message | 消息cause- the cause | 原因- Returns:
- the exception | 异常
-