Zend\Stratigility\Utils::getStatusCode PHP Method

getStatusCode() public static method

If the error is an exception with a code between 400 and 599, returns the exception code. Otherwise, retrieves the code from the response; if not present, or less than 400 or greater than 599, returns 500; otherwise, returns it.
public static getStatusCode ( mixed $error, Psr\Http\Message\ResponseInterface $response ) : integer
$error mixed
$response Psr\Http\Message\ResponseInterface
return integer
    public static function getStatusCode($error, ResponseInterface $response)
    {
        if (($error instanceof Throwable || $error instanceof Exception) && ($error->getCode() >= 400 && $error->getCode() < 600)) {
            return $error->getCode();
        }
        $status = $response->getStatusCode();
        if (!$status || $status < 400 || $status >= 600) {
            $status = 500;
        }
        return $status;
    }

Usage Example

 /**
  * Create/update the response representing the error.
  *
  * @param Throwable|Exception $e
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @return ResponseInterface
  */
 public function __invoke($e, ServerRequestInterface $request, ResponseInterface $response)
 {
     $response = $response->withStatus(Utils::getStatusCode($e, $response));
     $body = $response->getBody();
     if ($this->isDevelopmentMode) {
         $escaper = new Escaper();
         $body->write($escaper->escapeHtml((string) $e));
         return $response;
     }
     $body->write($response->getReasonPhrase() ?: 'Unknown Error');
     return $response;
 }
All Usage Examples Of Zend\Stratigility\Utils::getStatusCode