mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
fix(api): narrow swallowed database errors and redact the incident URL
The incident forwarder stripped the query string but not path-segment secrets from the reported URL; route it through the same redaction the message and stack already use. Several delete-and-swallow paths caught every error as the expected unique/absent-row case, masking real failures on security-notification, logout, and integration-disconnect paths and the Telegram reply-consume guard; narrow each to the specific Prisma code and let real failures surface.
This commit is contained in:
1 parent
9aa0a3597a
commit
336ce5aef3
10 files changed
+136
-22
No files matched your search
@@ -13,12 +13,27 @@
|
||||
* unique-constraint code.
|
||||
*/
|
||||
|
||||
/** Narrow a thrown Prisma error to the P2002 unique-constraint code. */
|
||||
export function isP2002(err: unknown): boolean {
|
||||
/** Narrow a thrown Prisma error to a specific known-request code. */
|
||||
function hasPrismaCode(err: unknown, code: string): boolean {
|
||||
return (
|
||||
typeof err === "object" &&
|
||||
err !== null &&
|
||||
"code" in err &&
|
||||
(err as { code: unknown }).code === "P2002"
|
||||
(err as { code: unknown }).code === code
|
||||
);
|
||||
}
|
||||
|
||||
/** Narrow a thrown Prisma error to the P2002 unique-constraint code. */
|
||||
export function isP2002(err: unknown): boolean {
|
||||
return hasPrismaCode(err, "P2002");
|
||||
}
|
||||
|
||||
/**
|
||||
* Narrow a thrown Prisma error to the P2025 "record not found" code — the
|
||||
* error `delete` / `update` raise when the target row no longer exists. Lets
|
||||
* an idempotent delete treat "already gone" as success while still surfacing a
|
||||
* genuine failure (a real DB fault raises a different code and rethrows).
|
||||
*/
|
||||
export function isP2025(err: unknown): boolean {
|
||||
return hasPrismaCode(err, "P2025");
|
||||
}
|
||||
Reference in new issue
Block a user