(error, context = 'Lookup')
| 1 | // Map axios/network errors to our shared envelope shape |
| 2 | export const upstreamError = (error, context = 'Lookup') => { |
| 3 | const status = error.response?.status; |
| 4 | if (status === 404 || status === 410) return { skipped: `No ${context} data for this host` }; |
| 5 | if (status === 401 || status === 403) return { error: `${context} blocked (HTTP ${status})` }; |
| 6 | if (status === 429) return { error: `${context} rate-limited by upstream` }; |
| 7 | if (status && status >= 500) return { error: `${context} upstream is unavailable` }; |
| 8 | if (error.code === 'ECONNABORTED') return { error: `${context} timed out` }; |
| 9 | if (error.code === 'ENOTFOUND') return { skipped: 'Host could not be resolved' }; |
| 10 | if (error.code === 'ECONNREFUSED') return { error: 'Connection refused by upstream' }; |
| 11 | return { error: `${context} failed: ${error.message}` }; |
| 12 | }; |
| 13 | |
| 14 | // Read a required env var, or return a skipped envelope if missing |
| 15 | export const requireEnv = (envVar, service) => { |
no outgoing calls
no test coverage detected