mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-30 08:10:23 +00:00
fix(server): match Hono wire format for authorize undefined and share errors (#26474)
This commit is contained in:
@@ -261,7 +261,7 @@ export const SessionApi = HttpApi.make("session")
|
|||||||
HttpApiEndpoint.post("share", SessionPaths.share, {
|
HttpApiEndpoint.post("share", SessionPaths.share, {
|
||||||
params: { sessionID: SessionID },
|
params: { sessionID: SessionID },
|
||||||
success: described(Session.Info, "Successfully shared session"),
|
success: described(Session.Info, "Successfully shared session"),
|
||||||
error: [HttpApiError.BadRequest, ApiNotFoundError],
|
error: [HttpApiError.InternalServerError, ApiNotFoundError],
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.share",
|
identifier: "session.share",
|
||||||
@@ -272,7 +272,7 @@ export const SessionApi = HttpApi.make("session")
|
|||||||
HttpApiEndpoint.delete("unshare", SessionPaths.share, {
|
HttpApiEndpoint.delete("unshare", SessionPaths.share, {
|
||||||
params: { sessionID: SessionID },
|
params: { sessionID: SessionID },
|
||||||
success: described(Session.Info, "Successfully unshared session"),
|
success: described(Session.Info, "Successfully unshared session"),
|
||||||
error: [HttpApiError.BadRequest, ApiNotFoundError],
|
error: [HttpApiError.InternalServerError, ApiNotFoundError],
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.unshare",
|
identifier: "session.unshare",
|
||||||
|
|||||||
@@ -61,9 +61,11 @@ export const providerHandlers = HttpApiBuilder.group(InstanceHttpApi, "provider"
|
|||||||
const payload = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(ProviderAuth.AuthorizeInput))(body).pipe(
|
const payload = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(ProviderAuth.AuthorizeInput))(body).pipe(
|
||||||
Effect.mapError(() => new HttpApiError.BadRequest({})),
|
Effect.mapError(() => new HttpApiError.BadRequest({})),
|
||||||
)
|
)
|
||||||
|
// Match legacy Hono behavior: when authorize() resolves without a
|
||||||
|
// result (e.g. no further redirect), serialize as JSON `null` instead
|
||||||
|
// of an empty body so clients can `.json()` parse the response.
|
||||||
const result = yield* authorize({ params: ctx.params, payload })
|
const result = yield* authorize({ params: ctx.params, payload })
|
||||||
if (result === undefined) return HttpServerResponse.empty({ status: 200 })
|
return HttpServerResponse.jsonUnsafe(result ?? null)
|
||||||
return HttpServerResponse.jsonUnsafe(result)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const callback = Effect.fn("ProviderHttpApi.callback")(function* (ctx: {
|
const callback = Effect.fn("ProviderHttpApi.callback")(function* (ctx: {
|
||||||
|
|||||||
@@ -213,13 +213,18 @@ export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "session",
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// share/unshare errors aren't all client-induced — storage and network
|
||||||
|
// failures from SessionShare are real possibilities. Map to a typed 500
|
||||||
|
// (matches the legacy Hono path which routed any failure through
|
||||||
|
// ErrorMiddleware → NamedError.Unknown 500) instead of blanket-mapping
|
||||||
|
// every failure to a 400 BadRequest.
|
||||||
const share = Effect.fn("SessionHttpApi.share")(function* (ctx: { params: { sessionID: SessionID } }) {
|
const share = Effect.fn("SessionHttpApi.share")(function* (ctx: { params: { sessionID: SessionID } }) {
|
||||||
yield* shareSvc.share(ctx.params.sessionID).pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))
|
yield* shareSvc.share(ctx.params.sessionID).pipe(Effect.mapError(() => new HttpApiError.InternalServerError({})))
|
||||||
return yield* SessionError.mapStorageNotFound(session.get(ctx.params.sessionID))
|
return yield* SessionError.mapStorageNotFound(session.get(ctx.params.sessionID))
|
||||||
})
|
})
|
||||||
|
|
||||||
const unshare = Effect.fn("SessionHttpApi.unshare")(function* (ctx: { params: { sessionID: SessionID } }) {
|
const unshare = Effect.fn("SessionHttpApi.unshare")(function* (ctx: { params: { sessionID: SessionID } }) {
|
||||||
yield* shareSvc.unshare(ctx.params.sessionID).pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))
|
yield* shareSvc.unshare(ctx.params.sessionID).pipe(Effect.mapError(() => new HttpApiError.InternalServerError({})))
|
||||||
return yield* SessionError.mapStorageNotFound(session.get(ctx.params.sessionID))
|
return yield* SessionError.mapStorageNotFound(session.get(ctx.params.sessionID))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user