propro-utils 1.7.31 → 1.7.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server/index.js +26 -5
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -251,13 +251,18 @@ class AuthMiddleware {
|
|
|
251
251
|
account: { accountId: account.accountId, email: account.email },
|
|
252
252
|
};
|
|
253
253
|
} catch (error) {
|
|
254
|
-
|
|
254
|
+
const status = error?.response?.status;
|
|
255
|
+
console.error(`Token refresh failed after ${Date.now() - startTime}ms (status: ${status}):`, error.message);
|
|
256
|
+
|
|
257
|
+
// Immediately clean up lock on failure to prevent blocking
|
|
258
|
+
this.refreshLocks.delete(lockKey);
|
|
259
|
+
|
|
255
260
|
throw error;
|
|
256
261
|
} finally {
|
|
257
|
-
// Clean up lock after 30 seconds
|
|
262
|
+
// Clean up lock after 30 seconds for successful requests
|
|
258
263
|
setTimeout(() => {
|
|
259
264
|
this.refreshLocks.delete(lockKey);
|
|
260
|
-
console.log('Refresh lock cleaned up');
|
|
265
|
+
console.log('Refresh lock cleaned up (delayed)');
|
|
261
266
|
}, 30000);
|
|
262
267
|
}
|
|
263
268
|
})();
|
|
@@ -270,11 +275,27 @@ class AuthMiddleware {
|
|
|
270
275
|
res.status(200).json(result);
|
|
271
276
|
} catch (error) {
|
|
272
277
|
console.error('Error refreshing token:', error);
|
|
278
|
+
|
|
279
|
+
const status = error?.response?.status || 401;
|
|
273
280
|
const errorMessage = error?.response?.data?.message || error?.message || 'Failed to refresh token';
|
|
274
|
-
|
|
281
|
+
|
|
282
|
+
// Pass through rate limit status
|
|
283
|
+
if (status === 429) {
|
|
284
|
+
const retryAfter = error?.response?.headers?.['retry-after'];
|
|
285
|
+
return res.status(429).json({
|
|
286
|
+
error: 'Too many requests',
|
|
287
|
+
message: 'Rate limit exceeded. Please try again later.',
|
|
288
|
+
retryAfter: retryAfter ? parseInt(retryAfter) : 900,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Handle 401 unauthorized
|
|
293
|
+
res.status(status).json({
|
|
275
294
|
error: 'Failed to refresh token',
|
|
276
295
|
message: errorMessage,
|
|
277
|
-
details:
|
|
296
|
+
details: status === 401
|
|
297
|
+
? 'Your session has expired. Please log in again.'
|
|
298
|
+
: 'Your session could not be refreshed. Please log in again.',
|
|
278
299
|
});
|
|
279
300
|
}
|
|
280
301
|
};
|