feat: Pick exception renderer based on the request's Accept header#17
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces Accept-header-driven exception handling for the Netlogix.WebApi package. A new PSR-15 middleware catches throwables thrown by downstream middlewares (so wrapping middlewares like Sitegeist.OffCORS:CorsMiddleware still see a real response) and delegates rendering to a dispatcher that picks a Flow ExceptionHandlerInterface implementation based on the request's Accept header. A JSON exception handler that matches the existing JsonViewHelper output shape is shipped, alongside default configuration plus a Development override.
Changes:
- New
ExceptionToResponseMiddlewareregistered afterSitegeist.OffCORS:CorsMiddleware, plusAcceptHeaderDependingExceptionHandlerdoing content negotiation and adaptingheader()/echo-style handlers to a PSR-7 response. - New
JsonExceptionHandlerrendering throwables as JSON (usingJsonSerializablewhen available, otherwise a generic status/reference payload). - Settings for
availableErrorHandlerswith JSON media-type entries and a*fallback (ProductionExceptionHandlerin default,DebugExceptionHandlerin Development) and README docs.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the new middleware, dispatcher, JSON handler, and configuration. |
| Configuration/Settings.Middleware.yaml | Registers ExceptionToResponseMiddleware directly after Sitegeist.OffCORS:CorsMiddleware. |
| Configuration/Settings.ExceptionHandler.yaml | Declares availableErrorHandlers per media type with JSON handlers and a ProductionExceptionHandler fallback. |
| Configuration/Development/Settings.ExceptionHandler.yaml | Overrides the * fallback with DebugExceptionHandler in Development. |
| Classes/Http/Middleware/ExceptionToResponseMiddleware.php | PSR-15 middleware that catches throwables and delegates to the dispatcher. |
| Classes/Error/AcceptHeaderDependingExceptionHandler.php | Negotiates an Accept-matching handler, captures its emitted headers/body, and returns a PSR-7 response. |
| Classes/Error/JsonExceptionHandler.php | Flow ExceptionHandlerInterface implementation emitting JSON error payloads. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0a13b96 to
b8e354b
Compare
18e9021 to
42a17fd
Compare
42a17fd to
7924cf2
Compare
No description provided.