-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.6] Throttle requests exception #23358
[5.6] Throttle requests exception #23358
Conversation
@@ -49,6 +50,7 @@ public function test_lock_opens_immediately_after_decay() | |||
try { | |||
$this->withoutExceptionHandling()->get('/'); | |||
} catch (Throwable $e) { | |||
$this->assertTrue($e instanceof ThrottleRequestsException); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use assertInstanceOf
instead
I personally like the idea - but this is a breaking change. Someone might be relying on the |
I'm not sure there is any breaking change here if it extends HttpException. Previous try / catch will still work and it won't be logged either since that is an instanceof check and it will still see the HttpException type. Am I wrong? |
Ah yes, good point @taylorotwell -- you are correct. |
@taylorotwell it will still catch it because of inheritance. |
@bencomeau - now I’m confused. If the whole point of this PR was to allow for ThrottlingExceptions to be logged, but they won’t be logged because of inheritance of HttpException - then that means this PR does not work as originally described? What am I missing?
|
TooManyRequestsHttpException already exists though... |
@laurencei Thanks, hopefully I can add some details to help clear up confusion! With this functionality, users can:
Beyond that, I suppose the bottom-line goal was to abstract the exception a bit so it could more fluidly be handled. @GrahamCampbell Thank you. I did notice this class existed in Symfony however given their handling of the parameters, I thought it was easier/cleaner to implement a different class. This is mostly based on the first parameter of the |
thanks @bencomeau |
I feel strongly it should. It is wrong for laravel to add it's own exception when one already exists, and should have been used. |
I think it was a mistake for symfony to make their http exception class not abstract tbh. |
@GrahamCampbell Okay, thanks for the feedback. I do understand why you strongly feel it should -- makes enough sense to me to not reinvent the wheel :) @taylorotwell Do you agree? Should I update this PR to extend Symfony's |
@bencomeau it has already been merged in you need to create a new one. |
Feature
I am proposing that the
ThrottleRequests
middleware throw a more specific exception as opposed to the current\Symfony\Component\HttpKernel\Exception\HttpException
.Reasoning
The
$dontReport
property of the exception handler class contains the\Symfony\Component\HttpKernel\Exception\HttpException::class
which means by default rate limiting will not be logged. If one wanted to log these events, they would need to update thereport
method of the exception handler class to something like:Furthermore, I don't believe they would be able to use Reportable Exceptions in this instance since the exception is thrown in the framework's middleware.
Solution
Create a new exception which the
ThrottleRequests
middleware can utilize; one that simply extends the\Symfony\Component\HttpKernel\Exception\HttpException
class. Add an additional test to theThrottleRequestsTest
to confirm the middleware is indeed throwing the desired exception.Final Thoughts
If approved, we may consider adding
\Illuminate\Http\Exceptions\ThrottleRequestsException::class
to the$dontReport
property of the exception handler class. Otherwise, this update would remove the long-standing functionality of not logging rate limiting by default. I would submit a pull request to thelaravel
repository depending on the outcome of this pull request.