/** * @param ClientException $exception * @return AuthException */ private function convertException($exception) { $authException = new AuthException($exception->getResponse()->getReasonPhrase(), $exception->getCode()); $authException->setUrl($exception->getResponse()->getEffectiveUrl()); $authException->setErrors(json_decode($exception->getResponse()->getBody()->getContents())); return $authException; }
public function handleHttpClientException(HttpClientException $e) { switch ($e->getResponse()->getStatusCode()) { case self::CONFLICT: throw new ProxyExistsException($e->getResponse()->getBody(), $e->getCode(), $e); case self::NOT_FOUND: throw new NotFoundException($e->getResponse()->getBody(), $e->getCode(), $e); case self::BAD_REQUEST: throw new InvalidToxicException($e->getResponse()->getBody(), $e->getCode(), $e); default: throw $e; } }
/** * Handles the Guzzle client exception. * * @param ClientException $e * @throws Unauthorized * @throws AddressNotFound */ protected function handleClientException(ClientException $e) { switch ($e->getCode()) { case 401: throw new Unauthorized(); case 404: throw new AddressNotFound(); } }
/** * Method to handle the selection of the correct exception to throw * * @param \GuzzleHttp\Exception\ClientException $e - Guzzle Client Exception * @return mixed - Exception to throw */ protected function handleException(ClientException $e) { switch ($e->getCode()) { case 401: return new UnauthorizedRequestException($e->getMessage()); break; case 404: return new MissingResourceException($e->getMessage()); break; case 429: return new RateLimitExceededException($e->getMessage()); break; default: return new RuntimeException($e->getMessage()); } }
/** * @param ClientException $e * * @return RequestException */ private function getCustomException(ClientException $e) { switch ($e->getCode()) { case 400: return new WadifyBadRequestException($e->getMessage(), $e->getRequest(), $e->getResponse()); case 401: return new WadifyAuthenticationException($e->getMessage(), $e->getRequest(), $e->getResponse()); case 403: return new WadifyAuthorizationException($e->getMessage(), $e->getRequest(), $e->getResponse()); default: return $e; } }
protected static function extractOriginalExceptionMessage(ClientException $exception) { self::$response = $exception->getResponse(); self::$stream = self::$response->getBody(); self::$content = self::$stream->getContents(); if (!self::$content) { throw new InstagramServerException($exception->getMessage(), $exception->getCode(), $exception); } return json_decode(self::$content); }
/** * Handle various Guzzle exceptions * * @param ConnectException|ClientException $exception Guzzle exception instance * * @return mixed[] $messages Array of errorCodes and messages */ protected function handleExceptions($exception) { $messages = array(); if ($exception instanceof ConnectException || $exception instanceof ClientException) { $messages = ['errorCode' => $exception->getCode(), 'message' => json_decode($exception->getResponseBodySummary($exception->getResponse()), true)['error']]; } else { } return $messages; }
private function supports(ClientException $exception, $map) { return array_key_exists($exception->getCode(), $map); }
/** * Turns a ClientException into a TiketException - like magic. * @param ClientException $exception - Guzzle ClientException * @return TiketException */ protected function convertException($exception) { $tiketException = new TiketException($exception->getResponse()->getReasonPhrase(), $exception->getCode()); $tiketException->setUrl($exception->getResponse()->getEffectiveUrl()); $tiketException->setErrors(json_decode($exception->getResponse()->getBody()->getContents())); return $tiketException; }