(
endpoint: PreflightEndpointCheck,
)
| 49 | try { |
| 50 | const endpoints = getPreflightEndpointChecks(); |
| 51 | const checkEndpoint = async ( |
| 52 | endpoint: PreflightEndpointCheck, |
| 53 | ): Promise<PreflightCheckResult> => { |
| 54 | try { |
| 55 | const response = await axios.request({ |
| 56 | url: endpoint.url, |
| 57 | method: endpoint.method, |
| 58 | data: endpoint.data, |
| 59 | timeout: 5000, |
| 60 | validateStatus: () => true, |
| 61 | headers: { |
| 62 | 'User-Agent': getUserAgent(), |
| 63 | ...endpoint.headers, |
| 64 | } |
| 65 | }); |
| 66 | if (!endpoint.expectedStatuses.includes(response.status)) { |
| 67 | const hostname = new URL(endpoint.url).hostname; |
| 68 | return { |
| 69 | success: false, |
| 70 | error: `Failed to connect to ${hostname}: Status ${response.status}` |
| 71 | }; |
| 72 | } |
| 73 | return { |
| 74 | success: true |
| 75 | }; |
| 76 | } catch (error) { |
| 77 | const hostname = new URL(endpoint.url).hostname; |
| 78 | const sslHint = getSSLErrorHint(error); |
| 79 | return { |
| 80 | success: false, |
| 81 | error: `Failed to connect to ${hostname}: ${error instanceof Error ? (error as ErrnoException).code || error.message : String(error)}`, |
| 82 | sslHint: sslHint ?? undefined |
| 83 | }; |
| 84 | } |
| 85 | }; |
| 86 | const results = await Promise.all(endpoints.map(checkEndpoint)); |
| 87 | const failedResult = results.find(result => !result.success); |
| 88 | if (failedResult) { |
nothing calls this directly
no test coverage detected