コード例 #1
0
 /**
  * Construct an instance from a PSR-7 response message.
  *
  * Here we can check for errors and return the appropriate error or error
  * collection object instead, avoiding the need for the factory every time?
  *
  * @param ResponseInterface $response
  * @returns static|ErrorCollection
  */
 public static function fromHttpResponse(ResponseInterface $response)
 {
     $httpCode = $response->getStatusCode();
     $data = static::parseBody($response);
     if ($httpCode >= Http::BAD_REQUEST || Helper::dataGet($data, 'errors')) {
         // 4xx and 5xx errors.
         // Return an error collection.
         return ErrorCollection::fromHttpResponse($response);
     }
     return static::fromData($data, $httpCode);
 }