Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/src/api-error.ts?version=28&format=json
49 linesFirst import 100%Last change First import in version 0, 1 version changed it

You're reading version 28. The newest is 318, and 1 version since then changed this file. Go to the newestCompare with 318

1// How a call to the server fails: an ApiError, and whether the request ever went out.
2
3export class ApiError extends Error {
4 readonly status: number | undefined;
5 /** The connection never opened, so the request never reached the server (safe to run again). */
6 readonly notSent: boolean;
7 constructor(message: string, status?: number, notSent = false) {
8 super(message);
9 this.name = "ApiError";
10 this.status = status;
11 this.notSent = notSent;
12 }
15/** Codes for a connection that never opened: the request never went out. */
16const NOT_SENT = new Set([
17 "UND_ERR_CONNECT_TIMEOUT",
18 "ECONNREFUSED",
19 "ENETUNREACH",
20 "EHOSTUNREACH",
21 "ENOTFOUND",
22 "EAI_AGAIN",
23 "EADDRNOTAVAIL",
24]);
26/** Whether a fetch failed before its request went out (connect timeout, refused, no route, no DNS answer). */
27export function neverSent(err: unknown): boolean {
28 const cause = (err as { cause?: { code?: string; errors?: readonly { code?: string }[] } }).cause;
29 if (cause === undefined) return false;
30 if (NOT_SENT.has(cause.code ?? "")) return true;
31 // Trying each address in turn (Node's autoSelectFamily) fails with every attempt's error.
32 return (
33 Array.isArray(cause.errors) &&
34 cause.errors.length > 0 &&
35 cause.errors.every((e) => NOT_SENT.has(e.code ?? "") || e.code === "ETIMEDOUT")
36 );
39/** The server's `{error: "sentence"}` answer, or the start of whatever it sent. */
40export function errorSentence(body: string): string {
41 try {
42 const parsed = JSON.parse(body) as { error?: unknown; reason?: unknown };
43 if (typeof parsed.error === "string") return parsed.error;
44 if (typeof parsed.reason === "string") return parsed.reason;
45 } catch {
46 // Not JSON.
47 }
48 return body.slice(0, 300);