Files
Unraid-AppOps-Gateway-Public/src/lib/operatorError.ts
T

17 lines
630 B
TypeScript

const invalidApiResponse = /unexpected token|doctype|not valid json|json parse|syntaxerror/i;
const htmlResponse = /<html|<!doctype|<body/i;
export const formatOperatorError = (error: unknown, fallback: string): string => {
const raw = error instanceof Error ? error.message : String(error || "");
const normalized = raw.trim();
if (!normalized) return fallback;
if (invalidApiResponse.test(normalized) || htmlResponse.test(normalized)) {
return `${fallback} De backendbron gaf geen geldige API-respons.`;
}
if (normalized.length > 240) {
return `${normalized.slice(0, 237)}...`;
}
return normalized;
};