/** * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable $next * * @return ResponseInterface */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { try { return $next($request, $response); } catch (Exception $e) { if ($this->logger) { $this->logger->error($e->getMessage(), ['exception' => $e]); } $type = $this->type($request); $response = $response->withHeader('Content-Type', $type); try { if (method_exists($e, 'getHttpStatus')) { $code = $e->getHttpStatus(); } else { $code = $e->getCode(); } $response = $response->withStatus($code); } catch (InvalidArgumentException $_) { // Exception did not contain a valid code $response = $response->withStatus(500); } if ($e instanceof HttpException) { $response = $e->withResponse($response); } $handler = $this->handler($type); $this->whoops->pushHandler($handler); $body = $this->whoops->handleException($e); $response->getBody()->write($body); $this->whoops->popHandler(); return $response; } }
/** * Set the proper Error Handler based on the Output of the page * * @param string $output */ public function setHandler($output = null) { $this->_whoops->popHandler(); if ($output == Output::JSON) { $this->_handler = new JsonResponseHandler(); } else { if ($output == Output::XML) { $this->_handler = new XmlResponseHandler(); } else { $this->_handler = new PlainResponseHandler(); } } $this->_whoops->pushHandler($this->_handler); }
/** * Set the proper Error Handler based on the Output of the page * * @param OutputData $output */ public function setHandler($output) { $this->_whoops->popHandler(); if ($output == OutputData::Json) { $this->_handler = new JsonResponseHandler(); } else { if ($output == OutputData::Xml) { $this->_handler = new XmlResponseHandler(); } else { $this->_handler = new PrettyPageHandler(); if (!Context::getInstance()->getDevelopmentStatus()) { $this->_handler->addResourcePath(\WhoopsResources\Resource::getPath()); } } } $this->_whoops->pushHandler($this->_handler); }
/** * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable $next * * @return ResponseInterface */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { try { return $next($request, $response); } catch (Exception $e) { $type = $this->type($request); $response = $response->withHeader('Content-Type', $type); try { $response = $response->withStatus($e->getCode()); } catch (InvalidArgumentException $_) { // Exception did not contain a valid code $response = $response->withStatus(500); } if ($e instanceof HttpException) { $response = $e->withResponse($response); } $handler = $this->handler($type); $this->whoops->pushHandler($handler); $body = $this->whoops->handleException($e); $response->getBody()->write($body); $this->whoops->popHandler(); return $response; } }
/** * Pops the last handler */ public function popHandler() { $this->errorHandler->popHandler(); }