Skip to content

feat: Pick exception renderer based on the request's Accept header#17

Merged
paxuclus merged 1 commit into
mainfrom
feat/VDEV-95-expose-exceptions-based-on-accept-header
May 29, 2026
Merged

feat: Pick exception renderer based on the request's Accept header#17
paxuclus merged 1 commit into
mainfrom
feat/VDEV-95-expose-exceptions-based-on-accept-header

Conversation

@stephanschuler
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ExceptionToResponseMiddleware registered after Sitegeist.OffCORS:CorsMiddleware, plus AcceptHeaderDependingExceptionHandler doing content negotiation and adapting header()/echo-style handlers to a PSR-7 response.
  • New JsonExceptionHandler rendering throwables as JSON (using JsonSerializable when available, otherwise a generic status/reference payload).
  • Settings for availableErrorHandlers with JSON media-type entries and a * fallback (ProductionExceptionHandler in default, DebugExceptionHandler in 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.

Comment thread Configuration/Settings.ExceptionHandler.yaml
Comment thread Configuration/Settings.ExceptionHandler.yaml Outdated
Comment thread Classes/Error/AcceptHeaderDependingExceptionHandler.php
Comment thread Classes/Error/JsonExceptionHandler.php
Comment thread Classes/Error/AcceptHeaderDependingExceptionHandler.php
Comment thread Classes/Error/AcceptHeaderDependingExceptionHandler.php
@stephanschuler stephanschuler force-pushed the feat/VDEV-95-expose-exceptions-based-on-accept-header branch 4 times, most recently from 0a13b96 to b8e354b Compare May 29, 2026 00:23
@stephanschuler stephanschuler marked this pull request as ready for review May 29, 2026 00:25
@stephanschuler stephanschuler force-pushed the feat/VDEV-95-expose-exceptions-based-on-accept-header branch 3 times, most recently from 18e9021 to 42a17fd Compare May 29, 2026 01:07
@stephanschuler stephanschuler requested a review from paxuclus May 29, 2026 05:39
Comment thread Configuration/Development/Settings.ExceptionHandler.yaml Outdated
Comment thread Configuration/Settings.Middleware.yaml Outdated
@stephanschuler stephanschuler force-pushed the feat/VDEV-95-expose-exceptions-based-on-accept-header branch from 42a17fd to 7924cf2 Compare May 29, 2026 07:23
@stephanschuler stephanschuler requested a review from paxuclus May 29, 2026 07:32
@paxuclus paxuclus merged commit a6412ec into main May 29, 2026
2 checks passed
@paxuclus paxuclus deleted the feat/VDEV-95-expose-exceptions-based-on-accept-header branch May 29, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants