Repository navigation
Add Symfony events for custom error responses - #8
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Symfony event dispatching to the API deprecation bundle, allowing applications to customize error responses for sunset and brownout scenarios instead of always throwing GoneHttpException. Two new events (ApiSunsetEvent and ApiBrownoutEvent) are dispatched before the exception is thrown, and listeners can set a custom Response on the event to override the default 410 behavior.
Changes:
- Added
ApiDeprecationEventbase class and two concrete event classes (ApiSunsetEvent,ApiBrownoutEvent) for sunset and brownout scenarios - Modified
DeprecationHeaderListenerto optionally accept anEventDispatcherInterfaceand dispatch events before throwingGoneHttpException, replacing the controller with a custom response closure when one is provided - Wired the
event_dispatcherservice (withnullOnInvalid()) into the listener via the bundle configuration
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Event/ApiDeprecationEvent.php | New abstract base event class holding the ApiDeprecated attribute, headers, and optional custom Response |
| src/Event/ApiSunsetEvent.php | Concrete event class for sunset (post-sunset 410) scenarios |
| src/Event/ApiBrownoutEvent.php | Concrete event class for brownout scenarios |
| src/EventListener/DeprecationHeaderListener.php | Dispatches events before throwing GoneHttpException; uses custom response if set |
| src/ApiDeprecationBundle.php | Injects optional event_dispatcher service into the listener |
| tests/EventListener/DeprecationHeaderListenerTest.php | Four new tests covering custom response and fallback behavior for both event types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Dispatch ApiSunsetEvent and ApiBrownoutEvent before throwing GoneHttpException, allowing applications to set a custom Response (e.g. RFC 9457 Problem Details) instead of the default plain-text 410. Falls back to existing behavior when no listener handles the event or no dispatcher is available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rflavien
force-pushed
the
feature/custom-error-response
branch
from
March 13, 2026 14:29
d55cb3f to
ec46cd4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
ApiSunsetEventandApiBrownoutEventevents dispatched before throwingGoneHttpExceptionResponseon the event to override the default 410 behaviorTest plan
🤖 Generated with Claude Code