[11.x] Add option to report throttled exception in ThrottlesExceptions middleware #50896
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds an option to the
ThrottlesExceptions
(andThrottlesExceptionsWithRedis
) middleware to have the throttled exception be reported. This will allow you to see the exception in your logging and be aware that something is not going as expected.Usage
Report every throttled exception:
Report only specific throttled exceptions:
N.B. I'll make a PR to the docs once this gets merged.
Motivation and context
I had one specific job that kept failing because of the max tries/timeout that was reached. I couldn't see why because I only saw the
MaxAttemptsExceededException
in my logging and nothing else. After debugging and seeing that theThrottlesExceptions
middleware we used, discards the exception, I disabled the middleware and I got the actual exception; it was trying to insert null in a non-nullable column. Afterwards I configured the middleware to only throttle specific exceptions, but that posibility wasn't documented, so I wasn't aware of this feature. So I also opened laravel/docs#9551 to document that. However, I still think this reporting feature is worth it and saves you a lot of debugging time!