mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 22:26:13 +00:00
feat(api): give every error envelope a meta.errorCode
Roughly half of the refusals answered prose alone, so a client could branch on the code for one 404 and had to fall back to the status for the next. apiHandler now completes every error envelope with the status's generic http.* code when the route named none; a route's own code still wins. The family joins the published catalogue, and the profile form only shows a code's sentence when the code has one.
This commit is contained in:
1 parent
c7f69fc212
commit
fbbb535832
11 files changed
+219
-50
No files matched your search
@@ -344,7 +344,7 @@ describe("POST /api/medications/[id]/intake/import — durable kickoff", () => {
|
||||
await expect(res.json()).resolves.toEqual({
|
||||
data: null,
|
||||
error: "Medication intake import already in progress",
|
||||
meta: { requestId: expect.any(String) },
|
||||
meta: { requestId: expect.any(String), errorCode: "http.conflict" },
|
||||
});
|
||||
expect(prisma.medicationIntakeImportJob.create).not.toHaveBeenCalled();
|
||||
expect(getGlobalBoss).not.toHaveBeenCalled();
|
||||
|
||||
@@ -122,7 +122,10 @@ describe("POST /api/settings/email/test", () => {
|
||||
|
||||
expect(response.status).toBe(500);
|
||||
const json = await response.json();
|
||||
expect(json.meta).toEqual({ requestId: expect.any(String) });
|
||||
expect(json.meta).toEqual({
|
||||
requestId: expect.any(String),
|
||||
errorCode: "http.internal",
|
||||
});
|
||||
});
|
||||
|
||||
it("answers a delivered test with 200", async () => {
|
||||
|
||||
@@ -187,7 +187,11 @@ describe("PUT /api/settings/webhook — private targets", () => {
|
||||
expect(response.status).toBe(422);
|
||||
const json = await response.json();
|
||||
expect(json.error).toBe("Invalid data");
|
||||
expect(json.meta).toEqual({ requestId: expect.any(String) });
|
||||
// No private-origin code: only the status's generic one.
|
||||
expect(json.meta).toEqual({
|
||||
requestId: expect.any(String),
|
||||
errorCode: "http.invalid",
|
||||
});
|
||||
});
|
||||
|
||||
it("saves a listed loopback target and refuses an unlisted one with the listable code", async () => {
|
||||
@@ -476,7 +480,10 @@ describe("POST /api/settings/{webhook,ntfy}/test — the refusal names itself",
|
||||
|
||||
expect(response.status).toBe(500);
|
||||
const json = await response.json();
|
||||
expect(json.meta).toEqual({ requestId: expect.any(String) });
|
||||
expect(json.meta).toEqual({
|
||||
requestId: expect.any(String),
|
||||
errorCode: "http.internal",
|
||||
});
|
||||
expect(emitIfSampledMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ level: "error" }),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user