MCPcopy Create free account
hub / github.com/massCodeIO/massCode / formatHttpRequestError

Function formatHttpRequestError

src/main/ipc/handlers/http.ts:296–331  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

294}
295
296export function formatHttpRequestError(error: unknown): string {
297 const candidates = collectErrorCandidates(error)
298 const detailedCandidates = candidates
299 .map(candidate => ({
300 message: formatDetailedRequestError(candidate),
301 record: asRecord(candidate),
302 }))
303 .filter(candidate => candidate.message)
304
305 const ipv4Detailed = detailedCandidates.find((candidate) => {
306 return stringValue(candidate.record?.address)?.includes('.') === true
307 })
308
309 if (ipv4Detailed?.message)
310 return ipv4Detailed.message
311
312 if (detailedCandidates[0]?.message)
313 return detailedCandidates[0].message
314
315 const causeMessage = getErrorMessage(getNestedCause(error))
316 if (causeMessage && causeMessage !== 'AggregateError')
317 return causeMessage
318
319 const nestedMessage = candidates
320 .slice(1)
321 .map(candidate => getErrorMessage(candidate))
322 .find(message => message && message !== 'AggregateError')
323
324 if (nestedMessage)
325 return nestedMessage
326
327 if (error instanceof Error && error.message)
328 return error.message
329
330 return String(error)
331}
332
333async function readBodyCapped(
334 body: NodeJS.ReadableStream,

Callers 2

http.test.tsFile · 0.90
executeHttpRequestFunction · 0.85

Calls 6

collectErrorCandidatesFunction · 0.85
stringValueFunction · 0.85
getNestedCauseFunction · 0.85
asRecordFunction · 0.70
getErrorMessageFunction · 0.70

Tested by

no test coverage detected