WIP! A BB-style forum, on the ATmosphere! We're still working... we'll be back soon when we have something to show off!
node typescript hono htmx atproto
at main 63 lines 1.9 kB view raw
1/** 2 * Check if an error is a programming error (code bug). 3 * Programming errors should be re-thrown, not caught. 4 */ 5export function isProgrammingError(error: unknown): boolean { 6 return ( 7 error instanceof TypeError || 8 error instanceof ReferenceError || 9 error instanceof SyntaxError 10 ); 11} 12 13/** 14 * Check if an error is a network error (temporary). 15 * Network errors should return 503 (retry later). 16 */ 17export function isNetworkError(error: unknown): boolean { 18 if (!(error instanceof Error)) return false; 19 const msg = error.message.toLowerCase(); 20 return ( 21 msg.includes("fetch failed") || 22 msg.includes("network") || 23 msg.includes("econnrefused") || 24 msg.includes("enotfound") || 25 msg.includes("timeout") || 26 msg.includes("etimedout") || 27 msg.includes("econnreset") || 28 msg.includes("enetunreach") || 29 msg.includes("service unavailable") 30 ); 31} 32 33/** 34 * Check if an error is an authentication error (wrong credentials). 35 * Auth errors should NOT be retried to avoid account lockouts. 36 */ 37export function isAuthError(error: unknown): boolean { 38 if (!(error instanceof Error)) return false; 39 const message = error.message.toLowerCase(); 40 return ( 41 message.includes("invalid identifier") || 42 message.includes("invalid password") || 43 message.includes("authentication failed") || 44 message.includes("unauthorized") 45 ); 46} 47 48/** 49 * Check if an error represents a database-layer failure. 50 * These errors indicate temporary unavailability — user should retry. 51 */ 52export function isDatabaseError(error: unknown): boolean { 53 if (!(error instanceof Error)) return false; 54 const msg = error.message.toLowerCase(); 55 return ( 56 msg.includes("pool") || 57 msg.includes("postgres") || 58 msg.includes("database") || 59 msg.includes("sql") || 60 // drizzle-orm wraps all failed queries as: "Failed query: <sql>\nparams: <params>" 61 msg.includes("failed query") 62 ); 63}