RFC 9457 Problem Details for HttpApi errors
I maintainer di solito rispondono entro 1 giorno
Una pull request collegata è già stata integrata.
- #9706 di @effect-bot — integrata
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 20/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- typescript
- Ambito
- backend-api-design
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 16.7k
- Fork
- 808
- Merge medio
- 12h 7m
- PR unite (30g)
- 844
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Effect-TS/effect
-
Support {self: this} for fnUntracedForse già presa @ArjunCodess l’ha presa 33 giorni fa. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Effect-TS/effect#8101 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
HttpApiClient: a path parameter of `.` or `..` changes the request pathForse già presa @effect-bot l’ha presa oggi. Aperta
Effect-TS/effect#9766 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Effect 3: add `~standard.jsonSchema` to `Schema.standardSchemaV1`Forse già presa @effect-bot l’ha presa oggi. Aperta
Effect-TS/effect#9765 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Support the `openapi-3.0` target in `Schema.toStandardJSONSchemaV1`Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertawontfix
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
-
`Schema.toStandardJSONSchemaV1` output has no `$schema`Forse già presa @gcanti l’ha presa oggi. Aperta
Effect-TS/effect#9763 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Effect-TS/effect
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
logto-io/logto#9837 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
lingdojo/kana-dojo#32964 · 1 commento · 5 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Documentation status: needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
mastra-ai/mastra#28194 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
priority-low refactor-3
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 3 giorni