Skip to content

Error Middleware Custom handler incorrect signature #598

Closed
@jelofson

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions