setApp($app); } protected App $app; public function setApp(App $app): Error { $this->app = $app; return $this; } public function getApp(): App { return $this->app; } public function __invoke(ServerRequestInterface $request, Throwable $exception, bool $displayErrorDetails, bool $logErrors, bool $logErrorDetails): ResponseInterface { error_log($exception); $response = $this->getApp()->getResponseFactory()->createResponse($exception->getCode()); $output = json_encode([ 'uri' => $request->getUri()->getPath(), 'code' => $exception->getCode(), 'message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace() ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); $response->getBody()->write($output); return $response->withHeader('Content-Type', 'application/json'); } }