Two related divergences from Hono are fixed in one move:
1. Status: many session handlers (todo, diff, summarize, fork, abort,
init, deleteMessage, command, shell, revert, unrevert) didn't wrap
with mapNotFound, so a thrown NotFoundError surfaced as a 500 defect
instead of a 404. The fork/diff endpoints also lacked OpencodeNotFound
in their declared error union, so handlers couldn't surface 404 even
if they wanted to.
2. Body shape: the existing mapNotFound rebrand to HttpApiError.NotFound
produced an empty 404 response. Hono returns the NamedError envelope
`{ name: "NotFoundError", data: { message } }`. SDK consumers reading
`error.data.message` got undefined.
The fix introduces OpencodeNotFound — a Schema.ErrorClass annotated with
`httpApiStatus: 404` and a body schema matching the legacy NamedError
shape. mapNotFound now rebrands NotFoundError to OpencodeNotFound,
preserving the underlying error message. All session endpoints that take
a sessionID now wrap their service calls with mapNotFound.
A TODO in the handler notes the long-term direction: services should
fail with typed errors directly (Effect<T, SessionNotFound>) and let
HttpApi auto-route status + body via schema annotations, eliminating
mapNotFound entirely. This PR is the pragmatic middle: small surface,
no service-layer changes, fixes the user-visible parity bug.
Unskips the two .todo parity reproducers in httpapi-parity.test.ts.
21 lines
680 B
TypeScript
21 lines
680 B
TypeScript
import { Schema } from "effect"
|
|
|
|
/**
|
|
* 404 Not Found error matching the legacy Hono `NamedError` JSON shape:
|
|
* `{ name: "NotFoundError", data: { message } }`.
|
|
*
|
|
* `httpApiStatus: 404` annotation drives the response status; the schema
|
|
* fields drive the response body. Use this in place of
|
|
* `HttpApiError.NotFound` (which has an empty body) anywhere SDK clients
|
|
* may inspect `error.data.message`.
|
|
*/
|
|
export class OpencodeNotFound extends Schema.ErrorClass<OpencodeNotFound>("opencode/Error/NotFound")(
|
|
{
|
|
name: Schema.tag("NotFoundError"),
|
|
data: Schema.Struct({ message: Schema.String }),
|
|
},
|
|
{
|
|
description: "Not found",
|
|
httpApiStatus: 404,
|
|
},
|
|
) {}
|