/**
  * Test invalid method returns the correct code and content type
  *
  * @dataProvider errorProvider
  */
 public function testError($contentType, $startOfBody)
 {
     $notAllowed = new Error();
     $e = new \Exception("Oops");
     /** @var Response $res */
     $res = $notAllowed->__invoke($this->getRequest('GET', $contentType), new Response(), $e);
     $this->assertSame(500, $res->getStatusCode());
     $this->assertSame($contentType, $res->getHeaderLine('Content-Type'));
     $this->assertEquals(0, strpos((string) $res->getBody(), $startOfBody));
 }
Esempio n. 2
0
 /**
  * Debugbar middleware invokable class
  *
  * @param  \Psr\Http\Message\ServerRequestInterface $request
  * @param  \Psr\Http\Message\ResponseInterface $response
  * @param  callable $next
  *
  * @return ResponseInterface
  */
 public function __invoke($request, $response, $next)
 {
     try {
         $response = $next($request, $response);
     } catch (Exception $e) {
         $this->debugbar->addException($e);
         // Handle the given exception
         $response = $this->error->__invoke($request, $response, $e);
     }
     // Modify the response to add the Debugbar
     $this->debugbar->modifyResponse($response);
     return $response;
 }
 public function __invoke(RequestInterface $request, ResponseInterface $response, \Exception $exception)
 {
     if ($exception instanceof InvalidArgumentException) {
         return $this->getBadRequestResponse($request, $response, $exception);
     } elseif ($exception instanceof NotFoundException) {
         return $this->getNotFoundResponse($request, $response, $exception);
     }
     return parent::__invoke($request, $response, $exception);
 }
Esempio n. 4
0
 /**
  * {inheritdoc}
  */
 protected function renderHtmlErrorMessage(Exception $exception)
 {
     if (is_null($this->view)) {
         return parent::renderHtmlErrorMessage($exception);
     }
     $title = 'Application Error';
     if ($this->displayErrorDetails) {
         $html = '<p>The application could not run because of the following error:</p>';
         $html .= '<h2>Details</h2>';
         $html .= $this->renderHtmlException($exception);
         while ($exception = $exception->getPrevious()) {
             $html .= '<h2>Previous exception</h2>';
             $html .= $this->renderHtmlException($exception);
         }
     } else {
         $html = '<p>A website error has occurred. Sorry for the temporary inconvenience.</p>';
     }
     $this->view->addData(compact('title', 'html'));
     return $this->view->render('error-500');
 }
Esempio n. 5
0
 public function __invoke(Request $request, Response $response, \Exception $exception)
 {
     // Log the message
     $this->logger->critical($exception->getMessage());
     return parent::__invoke($request, $response, $exception);
 }
Esempio n. 6
0
 /**
  * @param Container $container
  *
  */
 public function __construct(Container $container)
 {
     $this->logger = App::openLog('app.error');
     $this->view = $container['view'];
     parent::__construct();
 }