Adds safeParseJSON.ts file

pull/9078/head
Syed Ali Shahbaz 2022-10-07 12:43:47 +05:30 committed by GitHub
parent da88beb1f5
commit 12f54773f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -0,0 +1,8 @@
export default function parseJSONSafely(str: string) {
try {
return JSON.parse(str);
} catch (e) {
console.error((e as Error).message);
return {};
}
}