( error: unknown, seen = new Set<object>(), )
| 259 | } |
| 260 | |
| 261 | function getApiErrorCandidates( |
| 262 | error: unknown, |
| 263 | seen = new Set<object>(), |
| 264 | ): unknown[] { |
| 265 | if (!error || typeof error !== 'object') return [error] |
| 266 | if (seen.has(error)) return [] |
| 267 | seen.add(error) |
| 268 | |
| 269 | const candidates: unknown[] = [error] |
| 270 | const errorWithNested = error as { |
| 271 | lastError?: unknown |
| 272 | errors?: unknown[] |
| 273 | cause?: unknown |
| 274 | } |
| 275 | |
| 276 | candidates.push(...getApiErrorCandidates(errorWithNested.lastError, seen)) |
| 277 | |
| 278 | if (Array.isArray(errorWithNested.errors)) { |
| 279 | for (const nestedError of [...errorWithNested.errors].reverse()) { |
| 280 | candidates.push(...getApiErrorCandidates(nestedError, seen)) |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | candidates.push(...getApiErrorCandidates(errorWithNested.cause, seen)) |
| 285 | |
| 286 | return candidates |
| 287 | } |
| 288 | |
| 289 | function getApiErrorStatusCode(error: unknown): number | undefined { |
| 290 | if (!error || typeof error !== 'object') return undefined |
no outgoing calls
no test coverage detected