composer require netlogix/webapi
The package ships a PSR-15 middleware that catches exceptions inside the
middleware chain and turns them into a ResponseInterface. This way, any
response-decorating middleware (most importantly
Sitegeist.OffCORS:CorsMiddleware) sees a real response on errors and can
add its headers — which the default Flow exception path, running through
set_exception_handler, would bypass.
Netlogix\WebApi\Http\Middleware\ExceptionToResponseMiddlewareCatches anyThrowablethrown by downstream middlewares and delegates rendering to the dispatcher below. Registered viaConfiguration/Settings.Middleware.yamldirectly afterSitegeist.OffCORS:CorsMiddleware.Netlogix\WebApi\Error\AcceptHeaderDependingExceptionHandlerPicks one of the configured FlowExceptionHandlerInterfaceimplementations based on the request'sAcceptheader (proper content negotiation viaNeos\Flow\Http\Helper\MediaTypeHelper), invokes it, and adapts itsheader()/echostyle output into a PSR-7 response.Netlogix\WebApi\Error\JsonExceptionHandlerRenders the throwable as a jsonapi.org-style error document ({"errors": [{…}]}) mirroring the shape produced byNetlogix\JsonApiOrg\Controller\ApiController::errorAction(). For plain throwables the entry carriescodeandtitle, plus an optionalidfromWithReferenceCodeInterface. Production-safe variant — does not publish the exception message.Netlogix\WebApi\Error\JsonDebugExceptionHandlerSame envelope asJsonExceptionHandler, but for plain throwables the error entry additionally carriesdetail(the exception message) and ametablock withexceptionType,file,line, a sanitizedtrace(frame args stripped) and a recursivemeta.previouschain — analogous to howNeos\Flow\Error\DebugExceptionHandlerextends theProductionExceptionHandler. Reserved for non-production contexts.
Exceptions implementing JsonSerializable provide the body of one
error entry (the jsonapi.org fields, e.g. code / title /
detail / meta). Both handlers wrap that body in the standard
{"errors": […]} envelope, so the exception decides its own
representation but never the response shape.
Configure renderers per media type under
Netlogix.WebApi.error.availableErrorHandlers. The shape of the
options entry mirrors Flow's own Neos.Flow.error.exceptionHandler
(defaultRenderingOptions, renderingGroups, …), so the values can be
copy-pasted between the two.
Netlogix:
WebApi:
error:
availableErrorHandlers:
'application/vnd.api+json':
className: 'Netlogix\WebApi\Error\JsonExceptionHandler'
'application/json':
className: 'Netlogix\WebApi\Error\JsonExceptionHandler'
'*':
className: 'Neos\Flow\Error\ProductionExceptionHandler'
options:
defaultRenderingOptions:
renderTechnicalDetails: false
logException: true- Keys are IANA media types; the request's
Acceptheader is negotiated against them, respecting q-values and*/*ranges. - The special key
*is the fallback used when no configured media type matches the request's preferences. If*is missing and nothing else matches, the exception escapes back to Flow'sset_exception_handlerchain. - The shipped
Configuration/Development/Settings.ExceptionHandler.yamlswaps every renderer for its debug counterpart:Neos\Flow\Error\DebugExceptionHandlerfor the*fallback andNetlogix\WebApi\Error\JsonDebugExceptionHandlerfor both JSON media types — mirroring how Flow itself replaces the production handler with the debug variant in Development.
Logging is delegated entirely to the resolved Flow ExceptionHandler
(logException in its rendering options drives ThrowableStorage); the
middleware itself does not log.