Skip to content

Commit dbd48d4

Browse files
authored
fix(server): match Hono wire format for authorize undefined and share errors (anomalyco#26474)
1 parent e7cc825 commit dbd48d4

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

packages/opencode/src/server/routes/instance/httpapi/groups/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export const SessionApi = HttpApi.make("session")
261261
HttpApiEndpoint.post("share", SessionPaths.share, {
262262
params: { sessionID: SessionID },
263263
success: described(Session.Info, "Successfully shared session"),
264-
error: [HttpApiError.BadRequest, ApiNotFoundError],
264+
error: [HttpApiError.InternalServerError, ApiNotFoundError],
265265
}).annotateMerge(
266266
OpenApi.annotations({
267267
identifier: "session.share",
@@ -272,7 +272,7 @@ export const SessionApi = HttpApi.make("session")
272272
HttpApiEndpoint.delete("unshare", SessionPaths.share, {
273273
params: { sessionID: SessionID },
274274
success: described(Session.Info, "Successfully unshared session"),
275-
error: [HttpApiError.BadRequest, ApiNotFoundError],
275+
error: [HttpApiError.InternalServerError, ApiNotFoundError],
276276
}).annotateMerge(
277277
OpenApi.annotations({
278278
identifier: "session.unshare",

packages/opencode/src/server/routes/instance/httpapi/handlers/provider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ export const providerHandlers = HttpApiBuilder.group(InstanceHttpApi, "provider"
6161
const payload = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(ProviderAuth.AuthorizeInput))(body).pipe(
6262
Effect.mapError(() => new HttpApiError.BadRequest({})),
6363
)
64+
// Match legacy Hono behavior: when authorize() resolves without a
65+
// result (e.g. no further redirect), serialize as JSON `null` instead
66+
// of an empty body so clients can `.json()` parse the response.
6467
const result = yield* authorize({ params: ctx.params, payload })
65-
if (result === undefined) return HttpServerResponse.empty({ status: 200 })
66-
return HttpServerResponse.jsonUnsafe(result)
68+
return HttpServerResponse.jsonUnsafe(result ?? null)
6769
})
6870

6971
const callback = Effect.fn("ProviderHttpApi.callback")(function* (ctx: {

packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,18 @@ export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "session",
213213
return true
214214
})
215215

216+
// share/unshare errors aren't all client-induced — storage and network
217+
// failures from SessionShare are real possibilities. Map to a typed 500
218+
// (matches the legacy Hono path which routed any failure through
219+
// ErrorMiddleware → NamedError.Unknown 500) instead of blanket-mapping
220+
// every failure to a 400 BadRequest.
216221
const share = Effect.fn("SessionHttpApi.share")(function* (ctx: { params: { sessionID: SessionID } }) {
217-
yield* shareSvc.share(ctx.params.sessionID).pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))
222+
yield* shareSvc.share(ctx.params.sessionID).pipe(Effect.mapError(() => new HttpApiError.InternalServerError({})))
218223
return yield* SessionError.mapStorageNotFound(session.get(ctx.params.sessionID))
219224
})
220225

221226
const unshare = Effect.fn("SessionHttpApi.unshare")(function* (ctx: { params: { sessionID: SessionID } }) {
222-
yield* shareSvc.unshare(ctx.params.sessionID).pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))
227+
yield* shareSvc.unshare(ctx.params.sessionID).pipe(Effect.mapError(() => new HttpApiError.InternalServerError({})))
223228
return yield* SessionError.mapStorageNotFound(session.get(ctx.params.sessionID))
224229
})
225230

0 commit comments

Comments
 (0)