# Response generators and error listeners

For more information about using response generators and error listeners, see the HttpSoft\ErrorHandler\ErrorHandlerMiddleware description.

# Error response generators

Error response generators implement the HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface.

All generators contain only one public method HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface::generate().

public function generate(
    \Throwable $error, 
     Psr\Http\Message\ServerRequestInterface $request
): Psr\Http\Message\ResponseInterface;

# HttpSoft\Basis\ErrorHandler\ErrorResponseGenerator

Generates a response with information about the error according to the arguments passed to the constructor.

public function __construct(
    Psr\Http\Message\ResponseFactoryInterface $responseFactory,
    HttpSoft\Basis\TemplateRendererInterface $template,
    string $view, // Path to the view file.
    bool $debug = false
);

Source code on GitHub.

# HttpSoft\Basis\ErrorHandler\ErrorJsonResponseGenerator

Generates a response with information about the error in JSON format (HttpSoft\Response\JsonResponse).

public function __construct(bool $debug = false);

Source code on GitHub.

# Error listeners

Error listeners implement the HttpSoft\ErrorHandler\ErrorListenerInterface.

All listeners contain only one public method HttpSoft\ErrorHandler\ErrorListenerInterface::trigger().

public function trigger(
    \Throwable $error, 
     Psr\Http\Message\ServerRequestInterface $request
): void;

# HttpSoft\Basis\ErrorHandler\LogErrorListener

Logs information about the error.

public function __construct(Psr\Log\LoggerInterface $logger);

Source code on GitHub.