Adds meaningful response for the API caller
This commit is contained in:
1 parent
79fabe0333
commit
3bdebba21e
1 file changed
+6
@@ -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 {};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user