Braintree\Util::throwStatusCodeException PHP Method

throwStatusCodeException() public static method

throws an exception based on the type of error
public static throwStatusCodeException ( string $statusCode, null | string $message = null ) : void
$statusCode string HTTP status code to throw exception from
$message null | string
return void
    public static function throwStatusCodeException($statusCode, $message = null)
    {
        switch ($statusCode) {
            case 401:
                throw new Exception\Authentication();
                break;
            case 403:
                throw new Exception\Authorization($message);
                break;
            case 404:
                throw new Exception\NotFound();
                break;
            case 426:
                throw new Exception\UpgradeRequired();
                break;
            case 429:
                throw new Exception\TooManyRequests();
                break;
            case 500:
                throw new Exception\ServerError();
                break;
            case 503:
                throw new Exception\DownForMaintenance();
                break;
            default:
                throw new Exception\Unexpected('Unexpected HTTP_RESPONSE #' . $statusCode);
                break;
        }
    }

Usage Example

Exemplo n.º 1
0
 public function put($path, $params = null)
 {
     $response = $this->_doRequest('PUT', $path, $this->_buildXml($params));
     $responseCode = $response['status'];
     if ($responseCode === 200 || $responseCode === 201 || $responseCode === 422 || $responseCode == 400) {
         return Xml::buildArrayFromXml($response['body']);
     } else {
         Util::throwStatusCodeException($responseCode);
     }
 }
All Usage Examples Of Braintree\Util::throwStatusCodeException