MCPcopy
hub / github.com/rilldata/rill / extractErrorMessage

Function extractErrorMessage

web-common/src/lib/errors.ts:106–124  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

104 * and plain Error (message).
105 */
106export function extractErrorMessage(error: unknown): string {
107 if (!error || typeof error !== "object")
108 return String(error ?? "Unknown error");
109 const e = error as Record<string, unknown>;
110 // ConnectRPC error
111 if (typeof e.rawMessage === "string" && e.rawMessage) return e.rawMessage;
112 // HTTPError (Axios/REST)
113 const resp = e.response;
114 if (resp && typeof resp === "object") {
115 const data = (resp as Record<string, unknown>).data;
116 if (data && typeof data === "object") {
117 const msg = (data as Record<string, unknown>).message;
118 if (typeof msg === "string" && msg) return msg;
119 }
120 }
121 // Plain Error
122 if (typeof e.message === "string" && e.message) return e.message;
123 return "Unknown error";
124}
125
126/**
127 * Extracts an HTTP status code from any error shape.

Calls 1

StringFunction · 0.85

Tested by

no test coverage detected