(error: unknown)
| 93 | } |
| 94 | |
| 95 | function getPostgresErrorCode(error: unknown): string | null { |
| 96 | if (!error || typeof error !== 'object') { |
| 97 | return null |
| 98 | } |
| 99 | |
| 100 | let current: unknown = error |
| 101 | const seen = new Set<object>() |
| 102 | let depth = 0 |
| 103 | |
| 104 | while (current && typeof current === 'object' && depth < MAX_ERROR_CAUSE_DEPTH) { |
| 105 | if (seen.has(current)) { |
| 106 | return null // Circular reference detected |
| 107 | } |
| 108 | seen.add(current) |
| 109 | |
| 110 | const record = current as Record<string, unknown> |
| 111 | if (typeof record.code === 'string' && PG_ERROR_CODE_REGEX.test(record.code)) { |
| 112 | return record.code |
| 113 | } |
| 114 | |
| 115 | current = record.cause |
| 116 | depth += 1 |
| 117 | } |
| 118 | |
| 119 | return null |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Checks if an error is a retryable PostgreSQL error. |
no outgoing calls
no test coverage detected