feat(api): standardize errors as problem details

This commit is contained in:
dmg
2026-08-01 14:42:19 -04:00
parent 40abab7abc
commit 2657399628
16 changed files with 441 additions and 17 deletions
@@ -0,0 +1,18 @@
import { describe, expect, it } from "vitest";
import { GET } from "./route";
describe("unknown API routes", () => {
it("return an RFC 9457 not-found problem", async () => {
const response = GET(new Request("http://localhost/api/does-not-exist"));
expect(response.status).toBe(404);
expect(response.headers.get("content-type")).toBe("application/problem+json");
expect(await response.json()).toEqual({
type: "urn:error:not-found",
title: "API route not found",
status: 404,
detail: "The requested API route does not exist.",
instance: "/api/does-not-exist",
});
});
});
+20
View File
@@ -0,0 +1,20 @@
import { problemDetails } from "@minecraft-account-manager/contracts";
import { problemInstance, problemResponse } from "@/lib/problem-response";
function notFound(request: Request) {
const instance = problemInstance(request);
return problemResponse(problemDetails(
"urn:error:not-found",
"API route not found",
404,
"The requested API route does not exist.",
instance,
));
}
export const GET = notFound;
export const POST = notFound;
export const PUT = notFound;
export const PATCH = notFound;
export const DELETE = notFound;
export const OPTIONS = notFound;