19 lines
1001 B
TypeScript
19 lines
1001 B
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { checkServiceError, ServiceError } from "../lib/service-error";
|
|
|
|
test("backend failures use 503 and keep database internals out of browser errors", (t) => {
|
|
t.mock.method(console, "error", () => {});
|
|
assert.throws(() => checkServiceError({ code: "42P01", message: 'relation "private_table" does not exist' }), (error) => {
|
|
assert.ok(error instanceof ServiceError);
|
|
assert.equal(error.status, 503);
|
|
assert.doesNotMatch(error.message, /private_table|42P01/);
|
|
return true;
|
|
});
|
|
});
|
|
test("missing records and expected RPC validation keep actionable statuses and messages", () => {
|
|
assert.throws(() => checkServiceError({ code: "PGRST116", message: "no rows" }), (error) => error instanceof ServiceError && error.status === 404);
|
|
assert.throws(() => checkServiceError({ code: "P0001", message: "Guess outside map" }), /Guess outside map/);
|
|
assert.doesNotThrow(() => checkServiceError(null));
|
|
});
|