コード例 #1
0
ファイル: Api.php プロジェクト: picqer/gocardless-pro
 /**
  * @param BadResponseException $ex
  * @param array $response
  *
  * @throws AuthenticationException
  * @throws InvalidDocumentStructureException
  * @throws ResourceNotFoundException
  * @throws VersionNotFoundException
  */
 private function handleInvalidApiUsage(BadResponseException $ex, array $response)
 {
     switch ($response['error']['errors'][0]['reason']) {
         case 'resource_not_found':
             throw new ResourceNotFoundException(sprintf('Resource not found at %s', $ex->getRequest()->getRequestTarget()), $ex->getCode());
         case 'version_not_found':
             throw new VersionNotFoundException('Version not found', $ex->getCode());
         case 'invalid_document_structure':
             throw new InvalidDocumentStructureException($response['error']['message'], $ex->getCode());
         case 'access_token_not_found':
         case 'insufficient_permissions':
             throw new AuthenticationException($response['error']['message'], $ex->getCode());
     }
 }
コード例 #2
0
ファイル: GuzzleTimeline.php プロジェクト: link0/phpebble
 /**
  * @param BadResponseException $exception
  * @param Pin $pin
  *
  * @throws InvalidTimelineToken
  * @throws Exception
  */
 private function handleException(BadResponseException $exception, Pin $pin)
 {
     switch ($exception->getCode()) {
         case 400:
             // Invalid pin object
             throw new InvalidPinObject($pin);
         case 403:
             // Invalid API key
             throw new InvalidTimelineToken($this->token);
         case 410:
             // Invalid user token
             throw new InvalidTimelineToken($this->token);
         case 429:
             // Rate-limit exceeded
             throw new RateLimitExceeded();
         case 503:
             // Service unavailable
             throw new ServiceUnavailable();
     }
     throw new Exception("Invalid API call, reason unknown");
 }