Error Middleware Custom handler incorrect signature #598
Closed
Description
Hello,
In your example of a custom error handler you have this:
// Define Custom Error Handler
$customErrorHandler = function (
ServerRequestInterface $request,
Throwable $exception,
bool $displayErrorDetails,
bool $logErrors,
bool $logErrorDetails,
?LoggerInterface $logger = null
) use ($app) {
$logger->error($exception->getMessage());
$payload = ['error' => $exception->getMessage()];
$response = $app->getResponseFactory()->createResponse();
$response->getBody()->write(
json_encode($payload, JSON_UNESCAPED_UNICODE)
);
return $response;
};
However, the ?LoggerInterface $logger = null
will never be passed as the ErrorHandlerInterface does not accept a logger as the 6th param and the invoke of the handler looks like this:
return $handler($request, $exception, $this->displayErrorDetails, $this->logErrors, $this->logErrorDetails);
I am not sure if you want it to or not, but I thought I would let you know. In that example, you might have to get the logger some other way, such as in the use() statement.
Metadata
Assignees
Labels
No labels