mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-24 05:14:44 +00:00
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 * as Log from "@opencode-ai/core/util/log"
|
||||
import { ConfigError } from "@/config/error"
|
||||
import { Cause, Effect } from "effect"
|
||||
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)
|
||||
|
||||
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)}`
|
||||
|
||||
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* () {
|
||||
const configError = new ConfigError.InvalidError({
|
||||
path: "/tmp/opencode.json",
|
||||
@@ -68,9 +68,13 @@ describe("HttpApi error middleware", () => {
|
||||
|
||||
const response = yield* HttpClientRequest.get("/config-error").pipe(HttpClient.execute)
|
||||
const body = yield* response.json
|
||||
const serialized = JSON.stringify(body)
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
expect(JSON.stringify(body)).toBe(JSON.stringify(configError.toObject()))
|
||||
expect(response.status).toBe(500)
|
||||
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