• File: BadResponseCode.php
  • Full Path: /home/masbinta/public_html/core/vendor/facade/flare-client-php/src/Http/Exceptions/BadResponseCode.php
  • File size: 792 bytes
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace Facade\FlareClient\Http\Exceptions;

use Exception;
use Facade\FlareClient\Http\Response;

class BadResponseCode extends Exception
{
    /** @var \Facade\FlareClient\Http\Response */
    public $response;

    /** @var array */
    public $errors;

    public static function createForResponse(Response $response)
    {
        $exception = new static(static::getMessageForResponse($response));

        $exception->response = $response;

        $bodyErrors = isset($response->getBody()['errors']) ? $response->getBody()['errors'] : [];

        $exception->errors = $bodyErrors;

        return $exception;
    }

    public static function getMessageForResponse(Response $response)
    {
        return "Response code {$response->getHttpResponseCode()} returned";
    }
}