( error: unknown, )
| 58 | } |
| 59 | |
| 60 | const getTopLevelApiErrorDetails = ( |
| 61 | error: unknown, |
| 62 | ): { |
| 63 | statusCode?: number |
| 64 | errorCode?: string |
| 65 | message?: string |
| 66 | countryCode?: string |
| 67 | countryBlockReason?: string |
| 68 | ipPrivacySignals?: string[] |
| 69 | } => { |
| 70 | if (!error || typeof error !== 'object') return {} |
| 71 | const statusCode = (error as { statusCode?: unknown }).statusCode |
| 72 | const status = (error as { status?: unknown }).status |
| 73 | const errorCode = (error as { error?: unknown }).error |
| 74 | const message = (error as { message?: unknown }).message |
| 75 | const countryCode = (error as { countryCode?: unknown }).countryCode |
| 76 | const countryBlockReason = (error as { countryBlockReason?: unknown }) |
| 77 | .countryBlockReason |
| 78 | const ipPrivacySignals = (error as { ipPrivacySignals?: unknown }) |
| 79 | .ipPrivacySignals |
| 80 | const resolvedStatusCode = |
| 81 | typeof statusCode === 'number' |
| 82 | ? statusCode |
| 83 | : typeof status === 'number' |
| 84 | ? status |
| 85 | : undefined |
| 86 | |
| 87 | return { |
| 88 | ...(resolvedStatusCode !== undefined && { statusCode: resolvedStatusCode }), |
| 89 | ...(typeof errorCode === 'string' && { errorCode }), |
| 90 | ...(typeof message === 'string' && message.length > 0 && { message }), |
| 91 | ...(typeof countryCode === 'string' && |
| 92 | countryCode.length > 0 && { countryCode }), |
| 93 | ...(typeof countryBlockReason === 'string' && { countryBlockReason }), |
| 94 | ...(Array.isArray(ipPrivacySignals) && { |
| 95 | ipPrivacySignals: ipPrivacySignals.filter( |
| 96 | (signal): signal is string => typeof signal === 'string', |
| 97 | ), |
| 98 | }), |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | const getCliApiErrorDetails = (error: unknown) => { |
| 103 | const parsed = extractApiErrorDetails(error) |
no outgoing calls
no test coverage detected