Enum Class CommonResultCode
- All Implemented Interfaces:
ResultCode, Serializable, Comparable<CommonResultCode>, Constable
Common Result Code
通用响应码
Predefined common result codes for API responses.
API响应的预定义通用响应码。
Features | 主要功能:
- Comprehensive predefined result codes - 全面的预定义响应码
- HTTP status code mapping - HTTP 状态码映射
- Bilingual messages (English + Chinese) - 双语消息(英文 + 中文)
- Fast code lookup via static cache - 通过静态缓存快速查找代码
Code Format | 编码格式:
- Success: 00000 - 成功
- Client Error: A0xxx - 客户端错误
- Server Error: B0xxx - 服务端错误
- Third-party Error: C0xxx - 第三方错误
Usage Examples | 使用示例:
// Use in Result creation
Result<?> result = Result.fail(CommonResultCode.NOT_FOUND);
// Lookup by code string
CommonResultCode code = CommonResultCode.fromCode("A0404");
// Get HTTP status
int status = CommonResultCode.UNAUTHORIZED.getHttpStatus(); // 401
Security | 安全性:
- Thread-safe: Yes (enum, immutable) - 线程安全: 是(枚举,不可变)
- Null-safe: Yes (fromCode returns null for unknown codes) - 空值安全: 是(fromCode 对未知代码返回 null)
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescription -
Method Summary
Modifier and TypeMethodDescriptionstatic CommonResultCodeFind result code by code string 根据code字符串查找响应码static CommonResultCodefromCode(String code, CommonResultCode defaultCode) Find result code by code string with default 根据code字符串查找响应码(带默认值)getCode()Get the code 获取响应码intGet the HTTP status code 获取HTTP状态码Get the message 获取响应消息static CommonResultCodeReturns the enum constant of this class with the specified name.static CommonResultCode[]values()Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOfMethods inherited from interface ResultCode
isSuccess
-
Enum Constant Details
-
SUCCESS
-
CREATED
-
UPDATED
-
DELETED
-
ACCEPTED
-
NO_CONTENT
-
PARTIAL_CONTENT
-
QUEUED
-
PROCESSING
-
BAD_REQUEST
-
UNAUTHORIZED
-
FORBIDDEN
-
NOT_FOUND
-
METHOD_NOT_ALLOWED
-
NOT_ACCEPTABLE
-
REQUEST_TIMEOUT
-
CONFLICT
-
GONE
-
PAYLOAD_TOO_LARGE
-
URI_TOO_LONG
-
UNSUPPORTED_MEDIA_TYPE
-
VALIDATION_ERROR
-
LOCKED
-
TOO_MANY_REQUESTS
-
HEADER_TOO_LARGE
-
PARAM_MISSING
-
PARAM_INVALID
-
PARAM_TYPE_ERROR
-
PARAM_FORMAT_ERROR
-
PARAM_RANGE_ERROR
-
PARAM_LENGTH_ERROR
-
PARAM_PATTERN_ERROR
-
PARAM_DEPENDENCY_ERROR
-
TOKEN_EXPIRED
-
TOKEN_INVALID
-
PERMISSION_DENIED
-
ACCOUNT_LOCKED
-
ACCOUNT_DISABLED
-
ACCOUNT_NOT_VERIFIED
-
SESSION_EXPIRED
-
CREDENTIALS_INVALID
-
MFA_REQUIRED
-
MFA_INVALID
-
IP_BLOCKED
-
DEVICE_NOT_TRUSTED
-
FILE_NOT_FOUND
-
FILE_TYPE_NOT_ALLOWED
-
FILE_TOO_LARGE
-
FILE_EMPTY
-
FILE_UPLOAD_FAILED
-
FILE_CORRUPTED
-
FILE_VIRUS_DETECTED
-
RATE_LIMIT_EXCEEDED
-
QUOTA_EXCEEDED
-
CONCURRENT_LIMIT
-
DAILY_LIMIT_EXCEEDED
-
INTERNAL_ERROR
-
NOT_IMPLEMENTED
-
BAD_GATEWAY
-
SERVICE_UNAVAILABLE
-
GATEWAY_TIMEOUT
-
BANDWIDTH_LIMIT
-
BUSINESS_ERROR
-
DATA_NOT_FOUND
-
DATA_DUPLICATE
-
OPERATION_FAILED
-
INSUFFICIENT_BALANCE
-
ORDER_EXPIRED
-
INVENTORY_INSUFFICIENT
-
TRANSACTION_FAILED
-
WORKFLOW_ERROR
-
STATE_TRANSITION_ERROR
-
DATABASE_ERROR
-
DATABASE_TIMEOUT
-
DATABASE_CONNECTION_FAILED
-
CONSTRAINT_VIOLATION
-
DEADLOCK_DETECTED
-
DATA_INTEGRITY_ERROR
-
OPTIMISTIC_LOCK_ERROR
-
RESOURCE_BUSY
-
VERSION_CONFLICT
-
THIRD_PARTY_ERROR
-
REMOTE_SERVICE_ERROR
-
NETWORK_ERROR
-
EXTERNAL_API_ERROR
-
EXTERNAL_TIMEOUT
-
EXTERNAL_UNAVAILABLE
-
PAYMENT_FAILED
-
PAYMENT_DECLINED
-
PAYMENT_EXPIRED
-
REFUND_FAILED
-
SMS_SEND_FAILED
-
EMAIL_SEND_FAILED
-
PUSH_NOTIFICATION_FAILED
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getCode
Description copied from interface:ResultCodeGet the code 获取响应码- Specified by:
getCodein interfaceResultCode- Returns:
- the code | 响应码
-
getMessage
Description copied from interface:ResultCodeGet the message 获取响应消息- Specified by:
getMessagein interfaceResultCode- Returns:
- the message | 响应消息
-
getHttpStatus
public int getHttpStatus()Description copied from interface:ResultCodeGet the HTTP status code 获取HTTP状态码- Specified by:
getHttpStatusin interfaceResultCode- Returns:
- the HTTP status code | HTTP状态码
-
fromCode
Find result code by code string 根据code字符串查找响应码- Parameters:
code- the code | 响应码- Returns:
- result code or null | 响应码或null
-
fromCode
Find result code by code string with default 根据code字符串查找响应码(带默认值)- Parameters:
code- the code | 响应码defaultCode- the default code | 默认响应码- Returns:
- result code | 响应码
-