mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 04:51:51 +00:00
19 lines
424 B
TypeScript
19 lines
424 B
TypeScript
interface ErrorResult {
|
|
error?: string;
|
|
errors?: Array<{ detail?: string }>;
|
|
}
|
|
|
|
export function extractErrorMessage(
|
|
response: unknown,
|
|
fallback: string,
|
|
): string {
|
|
if (!response || typeof response !== "object") {
|
|
return fallback;
|
|
}
|
|
|
|
const responseRecord = response as ErrorResult;
|
|
const detailedError = responseRecord.errors?.[0]?.detail;
|
|
|
|
return detailedError || responseRecord.error || fallback;
|
|
}
|