Skip to content

Commit

Permalink
Merge pull request #27 from AtharvDalal/fix/limitConsumerPromiseHandler
Browse files Browse the repository at this point in the history
fix: add try-catch to limitConsumerPromiseHandler
  • Loading branch information
gobeam authored Feb 1, 2025
2 parents 4a624a3 + b13e389 commit 9b9a61b
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,14 @@ export class AuthService {
*/
async limitConsumerPromiseHandler(
usernameIPkey: string
): Promise<[RateLimiterRes, RateLimiterRes]> {
return new Promise((resolve) => {
this.rateLimiter
.consume(usernameIPkey)
.then((rateLimiterRes) => {
resolve([rateLimiterRes, null]);
})
.catch((rateLimiterError) => {
resolve([null, rateLimiterError]);
});
});
): Promise<[RateLimiterRes | null, RateLimiterRes | null]> {
try {
const rateLimiterRes = await this.rateLimiter.consume(usernameIPkey);
return [rateLimiterRes, null];
} catch (rateLimiterError) {
return [null, rateLimiterError];
}
}

/**
* get user profile
* @param user
Expand Down

0 comments on commit 9b9a61b

Please sign in to comment.