From 0ca0e94a6ad68824e33cf480163fe677210cb5cb Mon Sep 17 00:00:00 2001 From: Jay McDoniel Date: Thu, 6 Jul 2023 13:58:33 -0700 Subject: [PATCH] feat: add guard method for conditional skipping on override ref: #970 --- src/throttler.guard.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/throttler.guard.ts b/src/throttler.guard.ts index ec4be96e..98d768dc 100644 --- a/src/throttler.guard.ts +++ b/src/throttler.guard.ts @@ -58,6 +58,9 @@ export class ThrottlerGuard implements CanActivate { const handler = context.getHandler(); const classRef = context.getClass(); + if (await this.shouldSkip(context)) { + return true; + } const continues: boolean[] = []; for (const namedThrottler of this.throttlers) { // Return early if the current route should be skipped. @@ -89,6 +92,10 @@ export class ThrottlerGuard implements CanActivate { return continues.every((cont) => cont); } + protected async shouldSkip(_context: ExecutionContext): Promise { + return false; + } + /** * Throttles incoming HTTP requests. * All the outgoing requests will contain RFC-compatible RateLimit headers.