Example #1
0
 /**
  * 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);
 }
Example #2
0
 /**
  * {@inheritdoc}
  *
  * @param OutputInterface $output
  */
 public function handleSnapshot(SnapshotInterface $snapshot, OutputInterface $output = null)
 {
     if (empty($output)) {
         $output = new ConsoleOutput(OutputInterface::VERBOSITY_VERBOSE);
     }
     $this->application()->renderException($snapshot->getException(), $output);
 }
Example #3
0
 /**
  * {@inheritdoc}
  *
  * @param OutputInterface $output
  */
 public function handleSnapshot(SnapshotInterface $snapshot, OutputInterface $output = null)
 {
     //If no output provided we are probably handling fatal exception, let's verbose
     $output = !empty($output) ? $output : new ConsoleOutput(OutputInterface::VERBOSITY_VERBOSE);
     $this->application()->renderException($snapshot->getException(), $output);
 }
Example #4
0
 /**
  * {@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);
 }