fix(httpapi): return project not found errors (#28856)
This commit is contained in:
@@ -177,6 +177,15 @@ const scenarios: Scenario[] = [
|
||||
},
|
||||
"status",
|
||||
),
|
||||
http.protected
|
||||
.patch("/project/{projectID}", "project.update.missing")
|
||||
.mutating()
|
||||
.at((ctx) => ({
|
||||
path: route("/project/{projectID}", { projectID: "project_httpapi_missing" }),
|
||||
headers: ctx.headers(),
|
||||
body: { name: "Missing Project" },
|
||||
}))
|
||||
.json(404, object, "status"),
|
||||
http.protected
|
||||
.post("/project/git/init", "project.initGit")
|
||||
.mutating()
|
||||
|
||||
@@ -9,6 +9,7 @@ import { ControlPaths } from "../../src/server/routes/instance/httpapi/groups/co
|
||||
import { InstancePaths } from "../../src/server/routes/instance/httpapi/groups/instance"
|
||||
import { SessionPaths } from "../../src/server/routes/instance/httpapi/groups/session"
|
||||
import { PermissionID } from "../../src/permission/schema"
|
||||
import { ProjectID } from "../../src/project/schema"
|
||||
import { QuestionID } from "../../src/question/schema"
|
||||
import { HttpApiApp } from "../../src/server/routes/instance/httpapi/server"
|
||||
import { HEADER as FenceHeader } from "../../src/server/shared/fence"
|
||||
@@ -205,6 +206,30 @@ describe("instance HttpApi", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("returns typed not found bodies for missing projects", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
const projectID = ProjectID.make("project_missing")
|
||||
const response = yield* Effect.promise(() =>
|
||||
HttpApiApp.webHandler().handler(
|
||||
new Request(`http://localhost/project/${projectID}`, {
|
||||
method: "PATCH",
|
||||
headers: { "x-opencode-directory": dir, "content-type": "application/json" },
|
||||
body: JSON.stringify({ name: "Missing" }),
|
||||
}),
|
||||
handlerContext,
|
||||
),
|
||||
)
|
||||
|
||||
expect(response.status).toBe(404)
|
||||
expect(yield* Effect.promise(() => response.json())).toEqual({
|
||||
_tag: "ProjectNotFoundError",
|
||||
projectID,
|
||||
message: `Project not found: ${projectID}`,
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("serves path and VCS read endpoints", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
|
||||
@@ -208,4 +208,12 @@ describe("PublicApi OpenAPI v2 errors", () => {
|
||||
"PtyForbiddenError",
|
||||
)
|
||||
})
|
||||
|
||||
test("documents project not-found errors", () => {
|
||||
const spec = OpenApi.fromApi(PublicApi) as OpenApiSpec
|
||||
|
||||
expect(componentName(responseRef(spec.paths["/project/{projectID}"]?.patch?.responses?.["404"]) ?? "")).toBe(
|
||||
"ProjectNotFoundError",
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user