{"file":"client/src/api-error.ts","version":318,"total":62,"from":1,"to":62,"lines":[{"n":1,"text":"// How a call to the server fails: an ApiError, and whether the request ever went out.","atom":"a0","author":"init","version":0},{"n":2,"text":"","atom":"a0","author":"init","version":0},{"n":3,"text":"export class ApiError extends Error {","atom":"a0","author":"init","version":0},{"n":4,"text":"\treadonly status: number | undefined;","atom":"a0","author":"init","version":0},{"n":5,"text":"\t/** The connection never opened, so the request never reached the server (safe to run again). */","atom":"a0","author":"init","version":0},{"n":6,"text":"\treadonly notSent: boolean;","atom":"a0","author":"init","version":0},{"n":7,"text":"\tconstructor(message: string, status?: number, notSent = false) {","atom":"a0","author":"init","version":0},{"n":8,"text":"\t\tsuper(message);","atom":"a0","author":"init","version":0},{"n":9,"text":"\t\tthis.name = \"ApiError\";","atom":"a0","author":"init","version":0},{"n":10,"text":"\t\tthis.status = status;","atom":"a0","author":"init","version":0},{"n":11,"text":"\t\tthis.notSent = notSent;","atom":"a0","author":"init","version":0},{"n":12,"text":"\t}","atom":"a0","author":"init","version":0},{"n":13,"text":"}","atom":"a0","author":"init","version":0},{"n":14,"text":"","atom":"a0","author":"init","version":0},{"n":15,"text":"/** Codes for a connection that never opened: the request never went out. */","atom":"a0","author":"init","version":0},{"n":16,"text":"const NOT_SENT = new Set([","atom":"a0","author":"init","version":0},{"n":17,"text":"\t\"UND_ERR_CONNECT_TIMEOUT\",","atom":"a0","author":"init","version":0},{"n":18,"text":"\t\"ECONNREFUSED\",","atom":"a0","author":"init","version":0},{"n":19,"text":"\t\"ENETUNREACH\",","atom":"a0","author":"init","version":0},{"n":20,"text":"\t\"EHOSTUNREACH\",","atom":"a0","author":"init","version":0},{"n":21,"text":"\t\"ENOTFOUND\",","atom":"a0","author":"init","version":0},{"n":22,"text":"\t\"EAI_AGAIN\",","atom":"a0","author":"init","version":0},{"n":23,"text":"\t\"EADDRNOTAVAIL\",","atom":"a0","author":"init","version":0},{"n":24,"text":"]);","atom":"a0","author":"init","version":0},{"n":25,"text":"","atom":"a0","author":"init","version":0},{"n":26,"text":"/** Whether a fetch failed before its request went out (connect timeout, refused, no route, no DNS answer). */","atom":"a0","author":"init","version":0},{"n":27,"text":"export function neverSent(err: unknown): boolean {","atom":"a0","author":"init","version":0},{"n":28,"text":"\tconst cause = (err as { cause?: { code?: string; errors?: readonly { code?: string }[] } }).cause;","atom":"a0","author":"init","version":0},{"n":29,"text":"\tif (cause === undefined) return false;","atom":"a0","author":"init","version":0},{"n":30,"text":"\tif (NOT_SENT.has(cause.code ?? \"\")) return true;","atom":"a0","author":"init","version":0},{"n":31,"text":"\t// Trying each address in turn (Node's autoSelectFamily) fails with every attempt's error.","atom":"a0","author":"init","version":0},{"n":32,"text":"\treturn (","atom":"a0","author":"init","version":0},{"n":33,"text":"\t\tArray.isArray(cause.errors) &&","atom":"a0","author":"init","version":0},{"n":34,"text":"\t\tcause.errors.length > 0 &&","atom":"a0","author":"init","version":0},{"n":35,"text":"\t\tcause.errors.every((e) => NOT_SENT.has(e.code ?? \"\") || e.code === \"ETIMEDOUT\")","atom":"a0","author":"init","version":0},{"n":36,"text":"\t);","atom":"a0","author":"init","version":0},{"n":37,"text":"}","atom":"a0","author":"init","version":0},{"n":38,"text":"","atom":"a0","author":"init","version":0},{"n":39,"text":"/**","atom":"a456","author":"pinch","version":49},{"n":40,"text":" * The server's `{error: \"sentence\"}` answer, or the start of whatever it sent. An HTML page (the host's error","atom":"a456","author":"pinch","version":49},{"n":41,"text":" * page, when the server itself failed) is said by its title and Ray ID, which its first lines never reach.","atom":"a456","author":"pinch","version":49},{"n":42,"text":" */","atom":"a456","author":"pinch","version":49},{"n":43,"text":"export function errorSentence(body: string): string {","atom":"a0","author":"init","version":0},{"n":44,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":45,"text":"\t\tconst parsed = JSON.parse(body) as { error?: unknown; reason?: unknown };","atom":"a0","author":"init","version":0},{"n":46,"text":"\t\tif (typeof parsed.error === \"string\") return parsed.error;","atom":"a0","author":"init","version":0},{"n":47,"text":"\t\tif (typeof parsed.reason === \"string\") return parsed.reason;","atom":"a0","author":"init","version":0},{"n":48,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":49,"text":"\t\t// Not JSON.","atom":"a0","author":"init","version":0},{"n":50,"text":"\t}","atom":"a456","author":"pinch","version":49},{"n":51,"text":"\tif (/^\\s*<(!doctype html|html)/i.test(body)) {","atom":"a456","author":"pinch","version":49},{"n":52,"text":"\t\tconst plain = (s: string) =>","atom":"a456","author":"pinch","version":49},{"n":53,"text":"\t\t\ts","atom":"a456","author":"pinch","version":49},{"n":54,"text":"\t\t\t\t.replace(/<[^>]*>/g, \" \")","atom":"a456","author":"pinch","version":49},{"n":55,"text":"\t\t\t\t.replace(/\\s+/g, \" \")","atom":"a456","author":"pinch","version":49},{"n":56,"text":"\t\t\t\t.trim();","atom":"a456","author":"pinch","version":49},{"n":57,"text":"\t\tconst title = plain(/<title>([\\s\\S]*?)<\\/title>/i.exec(body)?.[1] ?? \"\");","atom":"a456","author":"pinch","version":49},{"n":58,"text":"\t\tconst ray = /Ray ID:\\s*(?:<[^>]*>\\s*)*([0-9a-f]+)/i.exec(body)?.[1];","atom":"a456","author":"pinch","version":49},{"n":59,"text":"\t\treturn `an HTML error page${title !== \"\" ? ` titled ${JSON.stringify(title)}` : \"\"}${ray ? ` (Ray ID ${ray})` : \"\"}, not the server's own answer: the server failed before it could say why`;","atom":"a456","author":"pinch","version":49},{"n":60,"text":"\t}","atom":"a0","author":"init","version":0},{"n":61,"text":"\treturn body.slice(0, 300);","atom":"a0","author":"init","version":0},{"n":62,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a456","author":"pinch","message":"","time":1791580249452,"timeIso":"2026-10-09T21:10:49.452Z","publish":{"draft":null,"version":49,"agent":"pinch","message":"Errors: say an HTML error page by its title and Ray ID\n\nWhen the server fails before it can answer, its host sends an HTML error page instead. The client printed the page's first 300 characters, which are all doctype and IE comments, so nobody could tell what had failed: \"GET /a/me/status answered 500: <!DOCTYPE html> <!--[if lt IE 7]> ...\".\n\nNow an HTML answer reads: answered 500: an HTML error page titled \"Worker threw exception | ... | Cloudflare\" (Ray ID ...), not the server's own answer: the server failed before it could say why. The title and Ray ID are what an operator needs to find the failure. JSON answers and plain text are said as before. Tested in error-sentence.test.ts.","time":1791580366631,"timeIso":"2026-10-09T21:12:46.631Z"}}]}