mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-13 15:44:56 +00:00
fix(server): remove storage not found defect fallback (#27287)
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { Provider } from "@/provider/provider"
|
import { Provider } from "@/provider/provider"
|
||||||
import { Session } from "@/session/session"
|
import { Session } from "@/session/session"
|
||||||
import { NotFoundError } from "@/storage/storage"
|
|
||||||
import { iife } from "@/util/iife"
|
import { iife } from "@/util/iife"
|
||||||
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"
|
||||||
@@ -24,10 +23,6 @@ export const errorLayer = HttpRouter.middleware<{ handles: unknown }>()((effect)
|
|||||||
const error = defect.defect
|
const error = defect.defect
|
||||||
log.error("failed", { error, cause: Cause.pretty(cause) })
|
log.error("failed", { error, cause: Cause.pretty(cause) })
|
||||||
|
|
||||||
if (error instanceof NotFoundError) {
|
|
||||||
return Effect.succeed(HttpServerResponse.jsonUnsafe(error.toObject(), { status: 404 }))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error instanceof NamedError) {
|
if (error instanceof NamedError) {
|
||||||
return Effect.succeed(
|
return Effect.succeed(
|
||||||
HttpServerResponse.jsonUnsafe(error.toObject(), {
|
HttpServerResponse.jsonUnsafe(error.toObject(), {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { describe, expect } from "bun:test"
|
|||||||
import { Effect, Layer } from "effect"
|
import { Effect, Layer } from "effect"
|
||||||
import { HttpClient, HttpClientRequest, HttpRouter } from "effect/unstable/http"
|
import { HttpClient, HttpClientRequest, HttpRouter } from "effect/unstable/http"
|
||||||
import { errorLayer } from "../../src/server/routes/instance/httpapi/middleware/error"
|
import { errorLayer } from "../../src/server/routes/instance/httpapi/middleware/error"
|
||||||
|
import { NotFoundError } from "../../src/storage/storage"
|
||||||
import { testEffect } from "../lib/effect"
|
import { testEffect } from "../lib/effect"
|
||||||
|
|
||||||
const it = testEffect(Layer.mergeAll(NodeHttpServer.layerTest, NodeServices.layer))
|
const it = testEffect(Layer.mergeAll(NodeHttpServer.layerTest, NodeServices.layer))
|
||||||
@@ -27,4 +28,23 @@ describe("HttpApi error middleware", () => {
|
|||||||
expect(JSON.stringify(body)).not.toContain("secret stack marker")
|
expect(JSON.stringify(body)).not.toContain("secret stack marker")
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
it.live("does not map storage not-found defects to 404", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
yield* HttpRouter.add(
|
||||||
|
"GET",
|
||||||
|
"/missing",
|
||||||
|
Effect.die(new NotFoundError({ message: "Resource not found: secret" })),
|
||||||
|
).pipe(Layer.provide(errorLayer), HttpRouter.serve, Layer.build)
|
||||||
|
|
||||||
|
const response = yield* HttpClientRequest.get("/missing").pipe(HttpClient.execute)
|
||||||
|
const body = yield* response.json
|
||||||
|
|
||||||
|
expect(response.status).toBe(500)
|
||||||
|
expect(body).toEqual({
|
||||||
|
name: "UnknownError",
|
||||||
|
data: { message: "Unexpected server error. Check server logs for details." },
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user