Пример #1
0
 /**
  * Transforms the exceptions thrown by \Guzzle\Http\Client
  * into Klout specific ones. If it doesn't know how to handle
  * the exception then it just re-throws it.
  *
  * @param  HttpRequestException        $e
  * @throws NotAuthorizedException
  * @throws ResourceNotFoundException
  * @throws ServiceUnavailableException
  * @throws Ambigous                    <HttpRequestException, \Guzzle\Http\Exception\ClientErrorResponseException, \Guzzle\Http\Exception\ServerErrorResponseException, \Guzzle\Http\Exception\MultiTransferException>
  * @return array:NULL
  */
 protected function handleHttpRequestException(HttpRequestException $e)
 {
     if ($e instanceof ClientErrorResponseException) {
         switch ($e->getResponse()->getStatusCode()) {
             case 403:
                 throw new NotAuthorizedException($e->getMessage());
                 break;
             case 404:
                 throw new ResourceNotFoundException($e->getMessage());
                 break;
         }
     } elseif ($e instanceof ServerErrorResponseException) {
         throw new ServiceUnavailableException($e->getMessage());
     } elseif ($e instanceof MultiTransferException) {
         if (count($e->getSuccessfulRequests()) == 0) {
             throw new ResourceNotFoundException($e->getMessage());
         }
         $responses = array();
         foreach ($e->getSuccessfulRequests() as $request) {
             $responses[] = $request->getResponse();
         }
         // In this case we return the valid responses
         return $responses;
     }
     // If we don't transform it to a Klout\Exception then
     // rethrow the original exception
     throw $e;
 }