Slim: Logger not forwarded to own ErrorHandlingMiddleware
As written in documentaton the customErrorHandler should receive the logger of the ErrorMiddleware as 6th parameter.
But unfortunately the customErrorHandler always receives null. This can be reproduced by just copying the code from the documentation.
Did some research and it seems the logger is not correctly submitted to the handler in the line below.
I’ve added $this->logger locally on my server and now my customErrorHandler gets the logger as intended.
I’m not aware of side effects this could have so created an issue here and no pull request.
Best.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 2
- Comments: 20 (16 by maintainers)
One thing to remember is that it couldn’t have been implemented in the original PR since we would have broken
ErrorHandlerInterface’s signature.At this point, I think it may be worth pushing any further changes to the next major version instead where we can rework how we interface with logging entirely:
$logErrorand$logErrorDetailsinErrorMiddlewareand migrate those to theLoggerclass’s constructor.ErrorHandlerInterface’s signature to acceptLoggerInterfaceand get rid of the two aforementioned extraneous params there as well.In the mean time, we should document this shortcoming in the docs. I think this may just be a trade-off of not breaking anything in a minor version.
@ddrv
I do agree that separating those concerns would make more sense:
ErrorMiddlewareErrorMiddlewaretoErrorHandlingMiddlewareErrorLoggingMiddlewareErrorLoggingMiddlewareshould be added beforeErrorHandlingMiddlewareand justcatch -> log -> rethrowsoErrorHandlingMiddlewarecan catch and handle.Relatively small changes for Slim 5 will at least make the upgrade path possible!