/** * Write snapshot content into exception. * * @param Request $request * @param Response $response * @param SnapshotInterface $snapshot * @return Response */ public function writeSnapshot(Request $request, Response $response, SnapshotInterface $snapshot) { //Exposing exception if ($request->getHeaderLine('Accept') != 'application/json') { $response->getBody()->write($snapshot->render()); //Normal exception page return $response->withStatus(ClientException::ERROR); } //Exception in a form of JSON object return $this->writeJson($response, $snapshot->describe(), ClientException::ERROR); }
/** * {@inheritdoc} * * @param bool $dispatch Snapshot will be automatically dispatched. * @param ServerRequestInterface $request Request caused snapshot. * @return ResponseInterface|null Depends of dispatching were requested. */ public function handleSnapshot(SnapshotInterface $snapshot, $dispatch = true, ServerRequestInterface $request = null) { if (empty($request)) { //Somewhere outside of dispatcher $request = $this->request(); } if (!$this->config['exposeErrors']) { //Http was not allowed to show any error snapshot to client $response = $this->exceptionResponse(new ServerErrorException(), $request); } else { if ($request->getHeaderLine('Accept') == 'application/json') { $context = ['status' => Response::SERVER_ERROR] + $snapshot->describe(); $response = new JsonResponse($context, Response::SERVER_ERROR); } else { $response = new HtmlResponse($snapshot->render(), Response::SERVER_ERROR); } } if (!$dispatch) { return $response; } return $this->dispatch($response); }