* fix: server side error handling * fix: push only unknown 500 errors to sentry * fix: use in-house onerror in favor of errorHandling middleware * fix: split error template into dev and prod envs * fix: check Error instance * fix: error routes in test env * fix: review comments * Remove koa-onerror Co-authored-by: Tom Moor <tom.moor@gmail.com>
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { getTestServer } from "@server/test/support";
|
|
|
|
const server = getTestServer();
|
|
|
|
describe("/test/error", () => {
|
|
it("should return error response as json", async () => {
|
|
const res = await server.post("/test/error", {
|
|
body: {},
|
|
});
|
|
const body = await res.json();
|
|
expect(res.status).toBe(500);
|
|
expect(body.message).toBe("Internal server error");
|
|
});
|
|
|
|
it("should return error response as html", async () => {
|
|
const res = await server.post("/test/error", {
|
|
headers: {
|
|
accept: "text/html",
|
|
},
|
|
body: {},
|
|
});
|
|
const body = await res.text();
|
|
expect(res.status).toBe(500);
|
|
expect(body).toContain("<title>Error - 500</title>");
|
|
});
|
|
|
|
it("should fallback to json err response for types other than html", async () => {
|
|
const res = await server.post("/test/error", {
|
|
headers: {
|
|
accept: "text/plain",
|
|
},
|
|
body: {},
|
|
});
|
|
const body = await res.json();
|
|
expect(res.status).toBe(500);
|
|
expect(body.message).toBe("Internal server error");
|
|
});
|
|
});
|