mirror of
https://github.com/baptisteArno/typebot.io.git
synced 2026-06-16 21:10:26 +08:00
🔧 Improve error details extraction
This commit is contained in:
parent
8771fd3c53
commit
cb931988e4
@ -21,24 +21,10 @@ export const parseUnknownError = async ({
|
||||
details: undefined,
|
||||
};
|
||||
if (err instanceof Error) {
|
||||
if (
|
||||
"response" in err &&
|
||||
typeof err.response === "object" &&
|
||||
err.response &&
|
||||
"text" in err.response &&
|
||||
typeof err.response.text === "function"
|
||||
) {
|
||||
return {
|
||||
context,
|
||||
description: err.message,
|
||||
details: await (err.response as Response).text(),
|
||||
};
|
||||
}
|
||||
return {
|
||||
context,
|
||||
description: err.message,
|
||||
details:
|
||||
typeof err.cause === "string" ? err.cause : JSON.stringify(err.cause),
|
||||
details: await extractDetails(err),
|
||||
};
|
||||
}
|
||||
return {
|
||||
@ -73,8 +59,7 @@ export const parseUnknownErrorSync = ({
|
||||
return {
|
||||
context,
|
||||
description: err.message,
|
||||
details:
|
||||
typeof err.cause === "string" ? err.cause : JSON.stringify(err.cause),
|
||||
details: extractDetailsSync(err),
|
||||
};
|
||||
}
|
||||
return {
|
||||
@ -89,3 +74,30 @@ export const parseUnknownErrorSync = ({
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const extractDetailsSync = (err: Error): string => {
|
||||
if ("responseBody" in err) {
|
||||
return typeof err.responseBody === "string"
|
||||
? err.responseBody
|
||||
: JSON.stringify(err.responseBody);
|
||||
}
|
||||
return typeof err.cause === "string" ? err.cause : JSON.stringify(err.cause);
|
||||
};
|
||||
|
||||
const extractDetails = async (err: Error): Promise<string> => {
|
||||
if ("responseBody" in err) {
|
||||
return typeof err.responseBody === "string"
|
||||
? err.responseBody
|
||||
: JSON.stringify(err.responseBody);
|
||||
}
|
||||
if (
|
||||
"response" in err &&
|
||||
typeof err.response === "object" &&
|
||||
err.response &&
|
||||
"text" in err.response &&
|
||||
typeof err.response.text === "function"
|
||||
) {
|
||||
return await (err.response as Response).text();
|
||||
}
|
||||
return typeof err.cause === "string" ? err.cause : JSON.stringify(err.cause);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user