Ajoute le detail des erreurs Postal
This commit is contained in:
+17
-2
@@ -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}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user