示例#1
0
 protected function checkHttpResponse(HttpClient $http)
 {
     $status = (int) $http->getStatus();
     if ($status === 401) {
         $this->errorCollection->add(array(new Error('Invalid credentials (401)', self::ERROR_CODE_INVALID_CREDENTIALS)));
     } elseif ($status === 403) {
         $headers = $http->getHeaders();
         $response = $http->getResult();
         $errorMessage = '';
         if ($response && is_string($response)) {
             $jsonResponse = Json::decode($response);
             if (isset($jsonResponse['error']['message'])) {
                 $errorMessage = $jsonResponse['error']['message'];
             }
             unset($jsonResponse, $response);
         }
         $headerAuthenticate = $headers->get('WWW-Authenticate');
         if (is_string($headerAuthenticate) && strpos($headerAuthenticate, 'insufficient') !== false) {
             $this->errorCollection->add(array(new Error('Insufficient scope (403)', self::ERROR_CODE_INSUFFICIENT_SCOPE)));
             return false;
         } elseif (strpos($errorMessage, 'The authenticated user has not installed the app with client') !== false) {
             $this->errorCollection->add(array(new Error('The authenticated user has not installed the app (403)', self::ERROR_CODE_NOT_INSTALLED_APP)));
         } elseif (strpos($errorMessage, 'The authenticated user has not granted the app') !== false) {
             $this->errorCollection->add(array(new Error('The authenticated user has not granted the app (403)', self::ERROR_CODE_NOT_GRANTED_APP)));
         } elseif (strpos($errorMessage, 'Invalid accessLevel') !== false) {
             $this->errorCollection->add(array(new Error('Invalid accessLevel (403)', self::ERROR_CODE_INVALID_ACCESS_LEVEL)));
         } elseif (strpos($errorMessage, 'is not properly configured as a Google Drive app') !== false) {
             $this->errorCollection->add(array(new Error('The app does not exist or is not properly configured as a Google Drive app (403)', self::ERROR_CODE_APP_NOT_CONFIGURED)));
         } elseif (strpos($errorMessage, 'is blacklisted') !== false) {
             $this->errorCollection->add(array(new Error('The app is blacklisted as a Google Drive app. (403)', self::ERROR_CODE_APP_IN_BLACKLIST)));
         } elseif ($errorMessage) {
             $this->errorCollection->add(array(new Error($errorMessage, self::ERROR_CODE_UNKNOWN)));
         }
     }
     if ($this->errorCollection->hasErrors()) {
         return false;
     }
     return parent::checkHttpResponse($http);
 }