RFC 9457 Problem Details for HttpApi errors
维护者通常 1 天内回复
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 20/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- typescript
调研方向
Start with packages/effect/src/http-api/HttpApiError.ts and the existing HttpApi middleware, schema, OpenAPI, and client paths named in the proposal. Review linked pull request #9706 and issue #5367 before considering scope; the issue leaves package placement and decode disclosure open. Done means implementing the proposed Problem Details schema, typed errors, opt-in rendering, OpenAPI support, and client decoding while preserving the default empty-body behavior.
由索引模型根据 Issue 内容生成。
描述
Problem
RFC 9457 (application/problem+json) is the standard JSON format for HTTP API errors. HttpApi doesn't support it, and by default its errors have no body:
- The built-in errors (
HttpApiError.BadRequest,NotFound, and so on) are sent as empty responses (packages/effect/src/http-api/HttpApiError.ts:23-56). - When a request fails to decode, the server answers with an empty
400(HttpApiError.ts:507). The client gets no indication of which field was wrong or why.
You can build Problem Details yourself with HttpApiMiddleware.layerSchemaErrorTransform and HttpApiSchema.asJson({ contentType }). But every project then writes its own schema, picks its own type, title and status defaults, and has to get the RFC's parsing rules right. For example, §3.1 says a member with the wrong JSON type is ignored, not rejected. #5367 asked for this in v3 and was closed with a workaround that re-encoded response bodies in a middleware. The people in that thread noted that the OpenAPI output then had to be patched as well.
Proposal
- A
ProblemDetailsvalue and Schema:typedefaults toabout:blank.status,title,detailandinstanceare optional.- Unknown members are kept as extensions.
- It decodes leniently, as §3.1 requires, and encodes canonically.
- A way to declare a typed problem: a fixed
typeURI with typed extension members, usable as an HttpApi error schema with the right status, media type and OpenAPI entry.
- An opt-in that renders HttpApi's own errors (decode failures and the built-ins) as Problem Details.
HttpApiClientdecodesapplication/problem+jsonresponses into the declared problem type.
// names illustrative
class OutOfCredit extends ProblemDetails.Type("https://example.com/probs/out-of-credit", {
status: 403,
balance: Schema.Number
}) {}
HttpApiEndpoint.post("buy", "/buy", { error: OutOfCredit })
Why in Effect
HttpApi owns both the mapping from errors to responses and the OpenAPI output, so this is the one place where it can be done without post-processing bodies and patching the spec. The format is widely supported elsewhere: ASP.NET Core (AddProblemDetails), Spring (ProblemDetail), and Rust's http-api-problem crate.
Scope
In scope:
- The value and Schema, typed problems, opt-in rendering, OpenAPI output and client decoding.
Out of scope:
application/problem+xml.- Changing the default empty-body behaviour without an opt-in.
Open questions
- Should this live in
effect/http, so it can be used without HttpApi, or ineffect/http-api? - How much should a decode failure reveal by default? The failing path and message help clients, but they also expose details of the schema.
- 主要语言
- TypeScript
- 星标
- 16.7k
- 派生
- 808
- 平均合并
- 10 小时 7 分钟
- 30 天内合并 PR
- 808
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Effect-TS/effect 的其他 Issue
-
Support {self: this} for fnUntraced可能已有人在做 @ArjunCodess 于 32 天前认领。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 70/100
Effect-TS/effect#8101 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 72/100
维护者通常 1 天内回复
-
v4 Cache.get: a caller that joins an abandoned lookup fails with an interruption it did not ask for未关闭
难度 4/5 3-5 天 新手友好度 42/100
维护者通常 1 天内回复
-
Typed unix socket and TLS options for `BunHttpClient` and `DenoHttpClient`可能已有人在做 @effect-bot 今天认领。 未关闭docker-made-me-do-it enhancement platform
Effect-TS/effect#9687 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Typed parsers and formatters for common HTTP header values可能已有人在做 @effect-bot 今天认领。 未关闭docker-made-me-do-it enhancement
Effect-TS/effect#9685 · 已指派 1 人 ·
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
endora-commerce/endora-commerce#397 ·
维护者通常 1 天内回复
-
level/task
难度 2/5 1-3 小时 新手友好度 68/100
wazuh/wazuh-dashboard-plugins#9472 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 63/100
维护者通常 1 天内回复
-
ready-for-agent
难度 2/5 1-3 小时 新手友好度 68/100
xavxyz/bei-shan-lin-shui#57 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
opennextjs/opennextjs-cloudflare#1461 ·
维护者通常 1 天内回复