public static function create(\GuzzleHttp\Exception\ServerException $e)
 {
     $message = sprintf('API server error (%s %s): %s on %s', $e->getResponse()->getStatusCode(), $e->getResponse()->getReasonPhrase(), $e->getMessage(), $e->getRequest()->getUri());
     return new self($message, $e->getResponse()->getStatusCode(), $e);
 }
 /**
  * Handle server error exceptions
  * 
  * @param \GuzzleHttp\Exception\ServerException $exc
  * @throws \WalmartApiClient\Exception\ApiBadGatewayException
  * @throws \WalmartApiClient\Exception\ApiServiceUnavailableException
  * @throws \WalmartApiClient\Exception\ApiGatewayTimeoutException
  * @throws \WalmartApiClient\Exception\ApiInternalServerErrorException
  */
 protected function handleServerException(\GuzzleHttp\Exception\ServerException $exc)
 {
     if ($exc->hasResponse() && $exc->getResponse()->getStatusCode() !== null) {
         $code = $exc->getResponse()->getStatusCode();
         switch ($code) {
             case 502:
                 throw new \WalmartApiClient\Exception\ApiBadGatewayException('Bad gateway', $code);
             case 503:
                 throw new \WalmartApiClient\Exception\ApiServiceUnavailableException('Service unavailable', $code);
             case 504:
                 throw new \WalmartApiClient\Exception\ApiGatewayTimeoutException('Gateway timeout', $code);
         }
     }
     throw new \WalmartApiClient\Exception\ApiInternalServerErrorException('Internal server error', 500);
 }
 public function __construct(ServerException $e)
 {
     parent::__construct($e->getMessage(), $e->getRequest(), $e->getResponse(), $e, $e->getHandlerContext());
 }
 protected function createApiMock($response, $statusCode = 200)
 {
     $jsonFile = $this->createJsonFile();
     $jobsMethods = array('collectCloverXml', 'getJsonFile', 'collectGitInfo', 'collectEnvVars', 'dumpJsonFile', 'send');
     $api = $this->getMockBuilder('Satooshi\\Bundle\\CoverallsV1Bundle\\Api\\Jobs')->disableOriginalConstructor()->setMethods($jobsMethods)->getMock();
     $api->expects($this->once())->method('collectCloverXml')->with()->will($this->returnSelf());
     $api->expects($this->once())->method('getJsonFile')->with()->will($this->returnValue($jsonFile));
     $api->expects($this->once())->method('collectGitInfo')->with()->will($this->returnSelf());
     $api->expects($this->once())->method('collectEnvVars')->with($this->equalTo($_SERVER))->will($this->returnSelf());
     $api->expects($this->once())->method('dumpJsonFile')->with()->will($this->returnSelf());
     $request = $this->getMockBuilder('\\GuzzleHttp\\Psr7\\Request')->setConstructorArgs(['POST', '/'])->getMock();
     if ($statusCode === 200) {
         $api->expects($this->once())->method('send')->with()->will($this->returnValue($response));
     } else {
         if ($statusCode === null) {
             $exception = \GuzzleHttp\Exception\ConnectException::create($request);
         } elseif ($statusCode === 422) {
             $exception = \GuzzleHttp\Exception\ClientException::create($request, $response);
         } else {
             $exception = \GuzzleHttp\Exception\ServerException::create($request, $response);
         }
         $api->expects($this->once())->method('send')->with()->will($this->throwException($exception));
     }
     return $api;
 }