Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function withStatus($code, $reasonPhrase = '')
 {
     $new = clone $this;
     $new->statusCode = HttpStatus::filterStatusCode($code);
     $new->reasonPhrase = $reasonPhrase;
     return $new;
 }
Esempio n. 2
0
 /**
  * Get the exception information.
  *
  * @param string $id
  * @param int    $code
  *
  * @return array
  */
 public function generate(string $id, int $code) : array
 {
     try {
         $info = ['id' => $id, 'code' => $code, 'name' => HttpStatus::getReasonPhrase($code), 'detail' => HttpStatus::getReasonMessage($code)];
     } catch (InvalidArgumentException $error) {
         $info = ['id' => $id, 'code' => 500, 'name' => HttpStatus::getReasonPhrase(500), 'detail' => HttpStatus::getReasonMessage(500)];
     }
     $info['summary'] = 'Houston, We Have A Problem.';
     return $info;
 }
Esempio n. 3
0
 public function testIfAllExceptionsAreExtendetFromTheRightClient()
 {
     $clientCount = 0;
     $serverCount = 0;
     foreach ($this->errorNames as $code => $text) {
         try {
             HttpStatus::getReasonException($code);
         } catch (Exception\AbstractClientErrorException $client) {
             ++$clientCount;
         } catch (Exception\AbstractServerErrorException $server) {
             ++$serverCount;
         }
     }
     $this->assertSame(27, $clientCount);
     $this->assertSame(11, $serverCount);
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function render(ServerRequestInterface $request, Throwable $exception) : ResponseInterface
 {
     $transformed = $this->getTransformed($exception);
     try {
         $response = $this->getResponse($this->getContainer()->get(ServerRequestInterface::class), $exception, $transformed);
         return $response;
     } catch (Throwable $error) {
         $this->report($error);
         $response = $this->getContainer()->get(ResponseInterface::class);
         $response = $response->withStatus(500, HttpStatus::getReasonPhrase(500));
         return $response;
     }
 }