Return detailed ACS error responses
This commit is contained in:
parent
c50b6ea499
commit
0cfe7522fd
1 changed files with 14 additions and 2 deletions
|
|
@ -134,12 +134,24 @@ const handleContact = async (request: Request, env: Env) => {
|
|||
},
|
||||
);
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
const contentType = response.headers.get("content-type") ?? "";
|
||||
const errorText = contentType.includes("application/json")
|
||||
? JSON.stringify(await response.json().catch(() => ({})))
|
||||
: await response.text();
|
||||
const errorCode = response.headers.get("x-ms-error-code");
|
||||
const details = [
|
||||
`${response.status} ${response.statusText}`.trim(),
|
||||
errorCode ? `code=${errorCode}` : "",
|
||||
errorText.trim(),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" | ")
|
||||
.slice(0, 500);
|
||||
return jsonResponse(
|
||||
{
|
||||
ok: false,
|
||||
error: "Failed to send email.",
|
||||
details: errorText.slice(0, 500),
|
||||
details,
|
||||
},
|
||||
502,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue