@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
47 lines • 1.63 kB
JavaScript
/** Read an error answer's body text. Never throws: a body that cannot be read is just absent. */
export function readErrorAnswer(text) {
if (text == null || text === '')
return { body: undefined, message: undefined, code: undefined };
let body = text;
try {
body = JSON.parse(text);
}
catch {
return { body: text, message: undefined, code: undefined };
}
if (body === null || typeof body !== 'object')
return { body, message: undefined, code: undefined };
const record = body;
const message = typeof record.message === 'string' && record.message !== ''
? record.message
: Array.isArray(record.message) &&
record.message.length > 0 &&
record.message.every((each) => typeof each === 'string')
? record.message.join('; ')
: undefined;
const code = typeof record.code === 'string' && record.code !== '' ? record.code : undefined;
return { body, message, code };
}
/** {@link readErrorAnswer} over a `Response` whose status is not 2xx. */
export async function readErrorResponse(response) {
let text;
try {
text = await response.text();
}
catch {
text = undefined;
}
return readErrorAnswer(text);
}
/** Tell `listener` about `error`; a listener that throws never replaces the error itself. */
export function reportHttpError(listener, error) {
if (listener === undefined)
return;
try {
listener(error);
}
catch {
/* the request's own error is what the caller gets */
}
}
//# sourceMappingURL=http-error.js.map