koajs / ratelimit

Rate limiter middleware
MIT License
485 stars 57 forks source link

Add option to throw error instead of setting body #13

Closed ruimarinho closed 8 years ago

ruimarinho commented 9 years ago

It can be useful to centralize all application errors in a single error handler, but currently this is not possible because the ratelimit middleware automatically handles it. My suggestion, implemented in this PR, is to pass a new option (throw: true) to throw the error instead, allowing a custom error handler to process it.

I considered making this the default option, since this.throw makes it somewhat compatible with koa's built-in error handler. However, this is not the case because all headers are removed from the response, so x-ratelimit-limit, x-ratelimit-remaining and x-ratelimit-reset would be missing from the response.

fixe commented 9 years ago

What about adding support for specifying headers in koa and making this the default? /cc @dead-horse

felixfbecker commented 8 years ago

Related https://github.com/koajs/koa/issues/571

haoxins commented 8 years ago

@koajs/ratelimit any more advice?

haoxins commented 8 years ago

land abf2924a0a9873b19432940bbf8c1edcd3cc84a3

haoxins commented 8 years ago

@ruimarinho koa-ratelimit@2.2.0