Skip to content

Commit

Permalink
Make VR API function fetch new token if token refresh fails (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
viliket committed Jun 14, 2024
1 parent 801d6ac commit 1e0ce5c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions functions/vr-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,16 @@ async function getToken(env: Env): Promise<AuthCredentials> {
}

if (now < new Date(existingAuthCredentials.refreshTokenExpiresOn)) {
const refreshedToken = await refreshToken(existingAuthCredentials, env);
await env.KV.put(authCredentialsCacheKey, JSON.stringify(refreshedToken));
return refreshedToken;
try {
const refreshedToken = await refreshToken(existingAuthCredentials, env);
await env.KV.put(
authCredentialsCacheKey,
JSON.stringify(refreshedToken)
);
return refreshedToken;
} catch (error) {
console.warn('Failed to refresh token:', error);
}
}
}

Expand Down

0 comments on commit 1e0ce5c

Please sign in to comment.