You are here

private function Client::handle4xx in Smart IP 7.2

Same name and namespace in other branches
  1. 6.2 includes/vendor/maxmind/web-service-common/src/WebService/Client.php \MaxMind\WebService\Client::handle4xx()

Parameters

int $statusCode The HTTP status code:

string $contentType The response content-type:

string $body The response body:

string $service The service name:

string $path The path used in the request:

Throws

AuthenticationException

HttpException

InsufficientFundsException

InvalidRequestException

1 call to Client::handle4xx()
Client::handleResponse in includes/vendor/maxmind/web-service-common/src/WebService/Client.php

File

includes/vendor/maxmind/web-service-common/src/WebService/Client.php, line 245

Class

Client
This class is not intended to be used directly by an end-user of a MaxMind web service. Please use the appropriate client API for the service that you are using. @package MaxMind\WebService @internal

Namespace

MaxMind\WebService

Code

private function handle4xx($statusCode, $contentType, $body, $service, $path) {
  if (strlen($body) === 0) {
    throw new HttpException("Received a {$statusCode} error for {$service} with no body", $statusCode, $this
      ->urlFor($path));
  }
  if (!strstr($contentType, 'json')) {
    throw new HttpException("Received a {$statusCode} error for {$service} with " . "the following body: " . $body, $statusCode, $this
      ->urlFor($path));
  }
  $message = json_decode($body, true);
  if ($message === null) {
    throw new HttpException("Received a {$statusCode} error for {$service} but could " . 'not decode the response as JSON: ' . $this
      ->jsonErrorDescription() . ' Body: ' . $body, $statusCode, $this
      ->urlFor($path));
  }
  if (!isset($message['code']) || !isset($message['error'])) {
    throw new HttpException('Error response contains JSON but it does not ' . 'specify code or error keys: ' . $body, $statusCode, $this
      ->urlFor($path));
  }
  $this
    ->handleWebServiceError($message['error'], $message['code'], $statusCode, $path);
}