Adds meaningful response for the API caller

This commit is contained in:
Syed Ali Shahbaz authored and GitHub committed 2022-10-07 13:12:57 +05:30
1 parent 79fabe0333
commit 3bdebba21e
1 file changed
+6
+6
View File
@@ -3,6 +3,12 @@ export default function parseJSONSafely(str: string) {
return JSON.parse(str);
} catch (e) {
console.error((e as Error).message);
if ((e as Error).message.includes("Unexpected token")) {
return {
success: false,
message: `Invalid JSON in the body: ${(e as Error).message}`,
};
}
return {};
}
}