Ajoute le detail des erreurs Postal

This commit is contained in:
2026-07-20 04:57:09 +02:00
parent a3a136c65d
commit 3510289bdb
5 changed files with 1562 additions and 5 deletions
+17 -2
View File
@@ -55,9 +55,24 @@ export function createPostalClient(options: CreatePostalClientOptions): PostalCl
})
});
const payload = (await response.json().catch(() => null)) as { status?: string } | null;
const rawBody = await response.text().catch(() => "");
const payload =
rawBody.length > 0
? (((() => {
try {
return JSON.parse(rawBody) as { status?: string; message?: string; error?: string };
} catch {
return null;
}
})()) ?? null)
: null;
if (!response.ok || payload?.status !== "success") {
throw new Error(`postal_send_failed:${response.status}`);
const details =
payload?.error?.trim() ||
payload?.message?.trim() ||
rawBody.trim().slice(0, 500) ||
"no_response_body";
throw new Error(`postal_send_failed:${response.status}:${details}`);
}
}
};