| 111 | } |
| 112 | |
| 113 | function getErrorCode(error: unknown): string | undefined { |
| 114 | let current = error |
| 115 | for (let depth = 0; depth < 5; depth += 1) { |
| 116 | if (!current || typeof current !== 'object') { |
| 117 | return undefined |
| 118 | } |
| 119 | if ( |
| 120 | 'code' in current && |
| 121 | typeof (current as { code?: unknown }).code === 'string' |
| 122 | ) { |
| 123 | return (current as { code: string }).code |
| 124 | } |
| 125 | if (!('cause' in current) || (current as { cause?: unknown }).cause === current) { |
| 126 | return undefined |
| 127 | } |
| 128 | current = (current as { cause?: unknown }).cause |
| 129 | } |
| 130 | return undefined |
| 131 | } |
| 132 | |
| 133 | function isAbortLike(error: unknown): boolean { |
| 134 | return error instanceof Error && error.name === 'AbortError' |