Skip to content

Commit

Permalink
Add try/catch around JSON.parse to avoid fail loop
Browse files Browse the repository at this point in the history
Signed-off-by: Cédric Boirard <cedric@framer.com>
  • Loading branch information
triozer committed Dec 3, 2024
1 parent e5234c0 commit fe474f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 8 additions & 4 deletions plugins/airtable/src/airtable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,15 @@ function getIgnoredFieldIds(rawIgnoredFieldIds: string | null) {
return []
}

const parsed = JSON.parse(rawIgnoredFieldIds)
if (!Array.isArray(parsed)) return []
if (!parsed.every(val => typeof val === "string")) return []
try {
const parsed = JSON.parse(rawIgnoredFieldIds)
if (!Array.isArray(parsed)) return []
if (!parsed.every(val => typeof val === "string")) return []

return parsed
return parsed
} catch {
return []
}
}

export async function getTableIdMapForBase(baseId: string | null): Promise<TableIdMap> {
Expand Down
10 changes: 7 additions & 3 deletions plugins/airtable/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ class Auth {
const serializedTokens = localStorage.getItem(this.PLUGIN_TOKENS_KEY)
if (!serializedTokens) return null

const storedTokens = JSON.parse(serializedTokens) as StoredTokens
this.storedTokens = storedTokens
try {
const storedTokens = JSON.parse(serializedTokens) as StoredTokens
this.storedTokens = storedTokens

return storedTokens
return storedTokens
} catch {
return null
}
},
clear: () => {
this.storedTokens = null
Expand Down

0 comments on commit fe474f2

Please sign in to comment.