Record Class ProblemDetail
java.lang.Object
java.lang.Record
cloud.opencode.base.web.problem.ProblemDetail
- Record Components:
type- the problem type URI, defaults to "about:blank" | 问题类型 URI,默认 "about:blank"title- the human-readable summary | 人类可读的摘要status- the HTTP status code | HTTP 状态码detail- the human-readable explanation | 人类可读的详细说明instance- the problem occurrence URI | 问题实例 URIextensions- the extension members | 扩展属性
public record ProblemDetail(String type, String title, int status, String detail, String instance, Map<String,Object> extensions)
extends Record
RFC 9457 Problem Details for HTTP APIs
RFC 9457 HTTP API 问题详情
A machine-readable format for conveying error details in HTTP response bodies, as defined by RFC 9457.
一种机器可读的格式,用于在 HTTP 响应体中传递错误详情, 由 RFC 9457 定义。
Features | 主要功能:
- RFC 9457 compliant problem details - 符合 RFC 9457 的问题详情
- Builder pattern for flexible construction - 构建器模式灵活构造
- Factory methods for common use cases - 常见场景的工厂方法
- Extension properties support - 扩展属性支持
- OpenWebException integration - OpenWebException 集成
Usage Examples | 使用示例:
// Quick creation
ProblemDetail problem = ProblemDetail.of(404, "User not found");
// With builder
ProblemDetail problem = ProblemDetail.builder()
.type("https://example.com/not-found")
.title("Not Found")
.status(404)
.detail("User with ID 42 was not found")
.instance("/users/42")
.extension("userId", 42)
.build();
// From exception
ProblemDetail problem = ProblemDetail.fromException(openWebException);
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: Yes (null fields treated as absent) - 空值安全: 是(null 字段视为缺失)
- Since:
- JDK 25, opencode-base-web V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for ProblemDetail ProblemDetail 构建器 -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ProblemDetail.Builderbuilder()Create a new Builder.detail()Returns the value of thedetailrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theextensionsrecord component.static ProblemDetailCreate a ProblemDetail from an OpenWebException.static ProblemDetailfromException(OpenWebException e, boolean includeCode) Create a ProblemDetail from an OpenWebException, optionally including the internal error code.Get the content type for problem detail responses.booleanCheck whether this problem has extension properties.final inthashCode()Returns a hash code value for this object.instance()Returns the value of theinstancerecord component.static ProblemDetailCreate a ProblemDetail with status and detail; title is auto-derived from status.static ProblemDetailCreate a ProblemDetail with status, title, and detail.intstatus()Returns the value of thestatusrecord component.title()Returns the value of thetitlerecord component.final StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.
-
Field Details
-
CONTENT_TYPE
Content-Type for problem details responses. 问题详情响应的 Content-Type。- See Also:
-
DEFAULT_TYPE
Default problem type URI as defined in RFC 9457. RFC 9457 定义的默认问题类型 URI。- See Also:
-
-
Constructor Details
-
ProblemDetail
-
-
Method Details
-
of
Create a ProblemDetail with status, title, and detail. 使用状态码、标题和详细说明创建 ProblemDetail。- Parameters:
status- the HTTP status code | HTTP 状态码title- the title | 标题detail- the detail | 详细说明- Returns:
- the problem detail | 问题详情
-
of
Create a ProblemDetail with status and detail; title is auto-derived from status. 使用状态码和详细说明创建 ProblemDetail;标题从状态码自动推导。- Parameters:
status- the HTTP status code | HTTP 状态码detail- the detail | 详细说明- Returns:
- the problem detail | 问题详情
-
fromException
Create a ProblemDetail from an OpenWebException. 从 OpenWebException 创建 ProblemDetail。- Parameters:
e- the exception | 异常- Returns:
- the problem detail | 问题详情
- Throws:
NullPointerException- if e is null | 如果 e 为 null
-
fromException
Create a ProblemDetail from an OpenWebException, optionally including the internal error code. 从 OpenWebException 创建 ProblemDetail,可选择是否包含内部错误码。- Parameters:
e- the exception | 异常includeCode- whether to include the internal error code in extensions | 是否在扩展中包含内部错误码- Returns:
- the problem detail | 问题详情
- Throws:
NullPointerException- if e is null | 如果 e 为 null
-
builder
Create a new Builder. 创建新的构建器。- Returns:
- the builder | 构建器
-
hasExtensions
public boolean hasExtensions()Check whether this problem has extension properties. 检查是否包含扩展属性。- Returns:
- true if extensions are present | 如果存在扩展属性返回 true
-
getContentType
Get the content type for problem detail responses. 获取问题详情响应的 Content-Type。- Returns:
- "application/problem+json"
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
type
-
title
-
status
-
detail
-
instance
-
extensions
Returns the value of theextensionsrecord component.- Returns:
- the value of the
extensionsrecord component
-