File size: 685 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import {
asOptionalBoolean,
asOptionalString,
asTrimmedString,
type AcpxErrorEvent,
isRecord,
} from "./shared.js";
export function parseControlJsonError(value: unknown): AcpxErrorEvent | null {
if (!isRecord(value)) {
return null;
}
const error = isRecord(value.error) ? value.error : null;
if (!error) {
return null;
}
const message = asTrimmedString(error.message) || "acpx reported an error";
const codeValue = error.code;
return {
message,
code:
typeof codeValue === "number" && Number.isFinite(codeValue)
? String(codeValue)
: asOptionalString(codeValue),
retryable: asOptionalBoolean(error.retryable),
};
}
|