refactor: eliminate all catch(err: any) with proper unknown typing + type email transport
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 19m10s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 19m10s
- Replace all catch(err: any) with catch(err: unknown) across 8 source files - Add errorMessage() and errorCode() helpers for safe error property access - Type nodemailer transport config as SMTPTransport.Options (was any) - Type health endpoint databaseStatus (was any) - Type convert route margin param (was any) - Change queryWithRetry params from any[] to unknown[] - Update isTransientError to require Error instances (was accepting plain objects) - 19 new TDD tests (error-type-safety.test.ts) - Updated existing tests to use proper Error instances - 598 tests total, all passing, zero type errors
This commit is contained in:
parent
da049b77e3
commit
5a7ee79316
12 changed files with 221 additions and 98 deletions
|
|
@ -16,10 +16,10 @@ const TRANSIENT_ERRORS = new Set([
|
|||
/**
|
||||
* Determine if an error is transient (PgBouncer failover, network blip)
|
||||
*/
|
||||
export function isTransientError(err: any): boolean {
|
||||
if (!err) return false;
|
||||
const code = err.code || "";
|
||||
const msg = (err.message || "").toLowerCase();
|
||||
export function isTransientError(err: unknown): boolean {
|
||||
if (!(err instanceof Error)) return false;
|
||||
const code = (err as Error & { code?: string }).code || "";
|
||||
const msg = err.message.toLowerCase();
|
||||
|
||||
if (TRANSIENT_ERRORS.has(code)) return true;
|
||||
if (msg.includes("no available server")) return true;
|
||||
|
|
@ -30,3 +30,20 @@ export function isTransientError(err: any): boolean {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract message from unknown error (safe for catch blocks).
|
||||
*/
|
||||
export function errorMessage(err: unknown): string {
|
||||
if (err instanceof Error) return err.message;
|
||||
if (typeof err === "string") return err;
|
||||
return String(err);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract error code from unknown error (e.g., PostgreSQL/Node error codes).
|
||||
*/
|
||||
export function errorCode(err: unknown): string | undefined {
|
||||
if (err instanceof Error && "code" in err) return (err as Error & { code?: string }).code;
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue