nestjs / throttler

A rate limiting module for NestJS to work with Fastify, Express, GQL, Websockets, and RPC 🧭

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal: Add `onLimit` option

friebetill opened this issue · comments

Are there considerations to add an onLimit option, e.g. like in this project GraphQL Rate Limit?

This would be useful so that one could, throw a GraphQLError directly with all the needed formatting (message, extension, ...).

Currently one can either:

  1. have extra logic for the ThrottlerException in the formatError method or
  2. override the handleRequest method to throw one's own exception.

Both are imho inelegant workarounds, but on the other side the feature is not a high priority. Probably there are other solutions, but these are the solutions I came up with.

What about adding in a new method for throwError that passes in the ExecutionContext, allowing for easy overriding?

Personally, I'd rather not pass methods through config if we can help it, as extending classes feels more natural in a class-based architecture.

You are right, a protected method throwError or maybe better throwException sounds more suitable.

Would you like to make a PR to add this?

Yes I can try it!