| 38 | // A thrown SDK error is transient if its status/code is retryable or its message |
| 39 | // looks like a timeout / throttle / dropped connection. |
| 40 | const thrownIsTransient = (e: unknown): boolean => { |
| 41 | const code = (e as any)?.code ?? (e as any)?.statusCode |
| 42 | if (typeof code === "number" && RETRYABLE_COSMOS_STATUS.has(code)) return true |
| 43 | const msg = e instanceof Error ? e.message : String(e) |
| 44 | return /request timed out|timed out|\btimeout\b|ETIMEDOUT|ECONNRESET|ECONNREFUSED|EAI_AGAIN|socket hang up|ServiceUnavailable|RequestTimeout|TooManyRequests|throttl/i |
| 45 | .test(msg) |
| 46 | } |
| 47 | |
| 48 | // Wrap a Cosmos SDK promise so a rejection becomes a typed, serializable |
| 49 | // `DatabaseError` (transient-classified) instead of a bare-`Error` defect — the |