MCPcopy Create free account
hub / github.com/Noumena-Network/code / checkEndpoints

Function checkEndpoints

src/utils/preflightChecks.tsx:48–111  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48async function checkEndpoints(): Promise<PreflightCheckResult> {
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) {
89 // Log failure to Statsig
90 logEvent('ncode_preflight_check_failed', {
91 isConnectivityError: false,
92 hasErrorMessage: !!failedResult.error,
93 isSSLError: !!failedResult.sslHint
94 });
95 }
96 return failedResult || {
97 success: true
98 };
99 } catch (error) {
100 logError(error as Error);
101
102 // Log to Statsig
103 logEvent('ncode_preflight_check_failed', {
104 isConnectivityError: true
105 });

Callers 1

runFunction · 0.85

Calls 3

logErrorFunction · 0.70
logEventFunction · 0.50

Tested by

no test coverage detected