feat(api): standardize errors as problem details
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { problemDetails, problemDetailsSchema } from "../src/index";
|
||||
|
||||
describe("RFC 9457 Problem Details", () => {
|
||||
it("builds the same problem shape as game-ingest-server", () => {
|
||||
const problem = problemDetails(
|
||||
"urn:error:invalid-velocity-access-request",
|
||||
"Invalid Velocity access request",
|
||||
400,
|
||||
"The request body does not match the required contract.",
|
||||
"/api/velocity/access",
|
||||
{ issues: [{ path: "minecraftUuid", message: "Invalid UUID" }] },
|
||||
);
|
||||
|
||||
expect(problemDetailsSchema.parse(problem)).toEqual({
|
||||
type: "urn:error:invalid-velocity-access-request",
|
||||
title: "Invalid Velocity access request",
|
||||
status: 400,
|
||||
detail: "The request body does not match the required contract.",
|
||||
instance: "/api/velocity/access",
|
||||
extensions: { issues: [{ path: "minecraftUuid", message: "Invalid UUID" }] },
|
||||
});
|
||||
});
|
||||
|
||||
it("omits optional members instead of serializing undefined values", () => {
|
||||
expect(problemDetails("urn:error:internal", "Internal server error", 500)).toEqual({
|
||||
type: "urn:error:internal",
|
||||
title: "Internal server error",
|
||||
status: 500,
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects values outside valid HTTP status codes", () => {
|
||||
expect(() => problemDetailsSchema.parse({ type: "urn:error:test", title: "Test", status: 42 }))
|
||||
.toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user