koajs / ratelimit

Rate limiter middleware
MIT License
485 stars 57 forks source link

Set 'Retry-After' header when throwing error #63

Closed mgrandrath closed 9 months ago

mgrandrath commented 3 years ago

This change sets the 'Retry-After' response header when throwing the 429 error (i.e. the throw option is set to true). Previously this was not the case because Koa's default error handler unsets all response headers before setting those specified in the error object.

I had to change the error handling in the tests because catching and handling the error bypassed Koa's error handler.

Please let me know if you have questions or suggestions