fix: standardize API responses for unknown routes

- Add a centralized not-found handler returning a consistent 404 response
- Assert the expected error payload for unknown endpoints
This commit is contained in:
Brandon Wolfgang 2026-10-21 19:58:54 -05:00
parent ca5ca12dba
commit 75bb74f5b3
2 changed files with 10 additions and 0 deletions

View file

@ -2,6 +2,7 @@ import assert from "node:assert";
import { after, describe, it } from "node:test";
import { buildApp } from "./server.js";
import { setServers } from "node:dns";
describe("API endpoints", () => {
const app = buildApp();
@ -119,6 +120,9 @@ describe("API endpoints", () => {
});
assert.equal(response.statusCode, 404);
assert.deepEqual(response.json(), {
error: "Not Found",
});
});
it("returns a generic 500 response for unexpected error", async () => {

View file

@ -24,6 +24,12 @@ export const buildApp = () => {
});
});
app.setNotFoundHandler((_request, reply) => {
return reply.code(404).send({
error: "Not Found",
});
});
app.get("/health", async () => ({
status: "ok",
}));