Skip to content

Commit

Permalink
Wrap JSON.parse method in try/catch block (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwm0 authored Dec 21, 2021
1 parent 013e001 commit 343eb56
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/apollo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ export const createFetch = ({
let token = storage.getAccessToken();
const authPluginId = storage.getAuthPluginId();

if (
["refreshToken", "externalRefresh"].includes(
JSON.parse(init.body?.toString() || "{}")?.operationName
)
) {
return fetch(input, init);
}
try {
if (
["refreshToken", "externalRefresh"].includes(
// INFO: Non-null assertion is enabled because the block is wrapped inside try/catch
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
JSON.parse(init.body!.toString()).operationName
)
) {
return fetch(input, init);
}
} catch (e) {}

if (autoTokenRefresh && token) {
// auto refresh token before provided time skew (in seconds) until it expires
Expand Down

0 comments on commit 343eb56

Please sign in to comment.