Skip to content

Commit

Permalink
fix: infinite refresh when unauthorized is used to ban account
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierJp committed Jan 17, 2024
1 parent 86ef13e commit 7cde289
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/utils/auth/api-rne/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,21 @@ const authApiRneClient = async (
}
return await callback();
} catch (e: any) {
console.log(e);
if (e instanceof HttpTooManyRequests) {
/**
* Either INPI returns too many requests or unauthorized
*
* Unauthorized can either be
* - token needs to be refresh
* - account is blocked
*
* In both case rotating account is safer
*/
if (
e instanceof HttpTooManyRequests ||
e instanceof HttpUnauthorizedError
) {
const shouldRotateAccount = true;
_token = await refreshToken(shouldRotateAccount);
}
if (e instanceof HttpUnauthorizedError) {
_token = await refreshToken();
return await callback();
} else {
throw e;
Expand Down

0 comments on commit 7cde289

Please sign in to comment.