mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-20 10:59:59 +00:00
Demonstrates the typed-errors-at-the-service-layer pattern on a single
method (`Session.Service.get`):
- Define `Session.SessionNotFound` as `Schema.ErrorClass` with
`httpApiStatus: 404` and a body shape that matches the existing Hono
`NamedError` envelope (`name: "NotFoundError"`, `data: { message }`).
- Update `Session.Service.Interface.get` and the implementation to fail
in the E channel via `yield* new SessionNotFound(...)`.
- HttpApi endpoint declares the typed error directly. The handler drops
its `mapNotFound` wrapper for `get` — Effect HttpApi auto-routes the
404 status from the schema annotation and serializes the body fields.
- Hono adapter (`runRequest`) bridges the typed error back to the
legacy `NotFoundError` defect so the existing `ErrorMiddleware` keeps
rendering 404 + body until that adapter is retired.
End-to-end validation: the unskipped parity test
(`Error JSON shape parity > HttpApi 404 body matches NamedError shape`)
now passes against the HttpApi adapter.
This is a sketch, not for merge — most cascading consumers are
absorbed via `Effect.orDie` (legacy never-E surface preserved). Real
rollout migrates each method/handler explicitly.