fix(httpapi): remove config error middleware special case (#28631)
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { NamedError } from "@opencode-ai/core/util/error"
|
import { NamedError } from "@opencode-ai/core/util/error"
|
||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
import { ConfigError } from "@/config/error"
|
|
||||||
import { Cause, Effect } from "effect"
|
import { Cause, Effect } from "effect"
|
||||||
import { HttpRouter, HttpServerError, HttpServerRespondable, HttpServerResponse } from "effect/unstable/http"
|
import { HttpRouter, HttpServerError, HttpServerRespondable, HttpServerResponse } from "effect/unstable/http"
|
||||||
|
|
||||||
@@ -19,13 +18,6 @@ export const errorLayer = HttpRouter.middleware<{ handles: unknown }>()((effect)
|
|||||||
if (!defect) return Effect.failCause(cause)
|
if (!defect) return Effect.failCause(cause)
|
||||||
|
|
||||||
const error = defect.defect
|
const error = defect.defect
|
||||||
if (
|
|
||||||
error instanceof NamedError &&
|
|
||||||
(ConfigError.InvalidError.isInstance(error) || ConfigError.JsonError.isInstance(error))
|
|
||||||
) {
|
|
||||||
return Effect.succeed(HttpServerResponse.jsonUnsafe(error.toObject(), { status: 400 }))
|
|
||||||
}
|
|
||||||
|
|
||||||
const ref = `err_${crypto.randomUUID().slice(0, 8)}`
|
const ref = `err_${crypto.randomUUID().slice(0, 8)}`
|
||||||
|
|
||||||
log.error("failed", { ref, error, cause: Cause.pretty(cause) })
|
log.error("failed", { ref, error, cause: Cause.pretty(cause) })
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ describe("HttpApi error middleware", () => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live("preserves config defects as client-visible bad requests", () =>
|
it.live("does not expose config defects from generic middleware", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const configError = new ConfigError.InvalidError({
|
const configError = new ConfigError.InvalidError({
|
||||||
path: "/tmp/opencode.json",
|
path: "/tmp/opencode.json",
|
||||||
@@ -68,9 +68,13 @@ describe("HttpApi error middleware", () => {
|
|||||||
|
|
||||||
const response = yield* HttpClientRequest.get("/config-error").pipe(HttpClient.execute)
|
const response = yield* HttpClientRequest.get("/config-error").pipe(HttpClient.execute)
|
||||||
const body = yield* response.json
|
const body = yield* response.json
|
||||||
|
const serialized = JSON.stringify(body)
|
||||||
|
|
||||||
expect(response.status).toBe(400)
|
expect(response.status).toBe(500)
|
||||||
expect(JSON.stringify(body)).toBe(JSON.stringify(configError.toObject()))
|
expectUnknownErrorBody(body)
|
||||||
|
expect(serialized).not.toContain("/tmp/opencode.json")
|
||||||
|
expect(serialized).not.toContain("provider")
|
||||||
|
expect(serialized).not.toContain("anthropic")
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user