Skip to content

Commit

Permalink
fix: throw exception on server error when refreshing token
Browse files Browse the repository at this point in the history
  • Loading branch information
mvantellingen committed Nov 26, 2024
1 parent 739e1d6 commit beda324
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/moody-geckos-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/federated-token-react": patch
---

throw exception on server error when refreshing token
15 changes: 14 additions & 1 deletion packages/react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,20 @@ export function AuthProvider({
credentials: "include",
});

return response.ok;
if (!response.ok) {
throw new Error("Failed to refresh token");
}

const data = await response.json();
if (!data) {
throw new Error("Failed to refresh token");
}

// Check if there is a GraphQL error
if (data.errors.length > 0) {
throw new Error("Failed to refresh token");
}
return true;
};

const clearTokens = async () => {
Expand Down

0 comments on commit beda324

Please sign in to comment.