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
Example #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);
     }
 }
Example #2
0
 /**
  * @expectedException Braintree\Exception\Unexpected
  */
 public function testThrowUnknownException()
 {
     Braintree\Util::throwStatusCodeException(999);
 }
 public function parseAndValidateQueryString($queryString)
 {
     // parse the params into an array
     parse_str($queryString, $params);
     // remove the hash
     $queryStringWithoutHash = null;
     if (preg_match('/^(.*)&hash=[a-f0-9]+$/', $queryString, $match)) {
         $queryStringWithoutHash = $match[1];
     }
     if ($params['http_status'] != '200') {
         $message = null;
         if (array_key_exists('bt_message', $params)) {
             $message = $params['bt_message'];
         }
         Util::throwStatusCodeException(isset($params['http_status']) ? $params['http_status'] : null, $message);
     }
     // recreate the hash and compare it
     if ($this->_hash($queryStringWithoutHash) == $params['hash']) {
         return $params;
     } else {
         throw new Exception\ForgedQueryString();
     }
 }