Example #1
0
 /**
  * Handles the error for us, just a bit of code abstraction.
  *
  * @param BadResponseException $exception
  *
  * @throws JSONError
  */
 public static function handleError(BadResponseException $exception)
 {
     $response_body = (string) $exception->getResponse()->getBody();
     $array_body = decode($response_body);
     $code = $exception->getResponse()->getStatusCode();
     $message = null;
     if (isset($array_body['message'])) {
         $message = $array_body['message'];
     } elseif (isset($array_body['code'])) {
         $message = $array_body['code'];
     }
     throw new JSONError($message, $code, $array_body);
 }
Example #2
0
 /**
  * Build a new object from a JSON string rather than array.
  *
  * @param string $json
  *
  * @return self
  */
 public static function buildFromJson(string $json)
 {
     return new self(decode($json));
 }