You are here

protected function EndpointAccessibilityRequirement::parseStatusCode in Acquia Content Hub 8

Parse the status code and return the error, if applicable.

Parameters

int $status_code: Status code of response.

string $endpoint_name: Human readable name of endpoint.

string $endpoint_url: Url of endpoint.

Return value

string Error to be added to the description.

2 calls to EndpointAccessibilityRequirement::parseStatusCode()
EndpointAccessibilityRequirement::testContentViewEndpoint in acquia_contenthub_diagnostic/src/Plugin/ContentHubRequirement/EndpointAccessibilityRequirement.php
Test the content view endpoint.
EndpointAccessibilityRequirement::testWebhookEndpoint in acquia_contenthub_diagnostic/src/Plugin/ContentHubRequirement/EndpointAccessibilityRequirement.php
Test the webhook endpoint.

File

acquia_contenthub_diagnostic/src/Plugin/ContentHubRequirement/EndpointAccessibilityRequirement.php, line 161

Class

EndpointAccessibilityRequirement
Defines an endpoint accessibility requirement.

Namespace

Drupal\acquia_contenthub_diagnostic\Plugin\ContentHubRequirement

Code

protected function parseStatusCode($status_code, $endpoint_name, $endpoint_url) {

  // 200 response is the only successful response.
  if ($status_code == 200) {
    return '';
  }
  elseif (substr($status_code, 0, 1) == 3) {
    return $this
      ->t("@endpoint_name (@endpoint_url) received a @status_code response indicating a redirect. The Content Hub service will not follow redirects.\n", [
      '@endpoint_name' => $endpoint_name,
      '@endpoint_url' => $endpoint_url,
      '@status_code' => $status_code,
    ]);
  }
  elseif ($status_code == 401) {
    return $this
      ->t("@endpoint_name (@endpoint_url) received a 401 response indicating that credentials are required. Disable the Shield module or any other authentication method being used on the endpoint.\n", [
      '@endpoint_name' => $endpoint_name,
      '@endpoint_url' => $endpoint_url,
    ]);
  }
  elseif ($status_code == 404) {
    return $this
      ->t("@endpoint_name (@endpoint_url) received a 404 response indicating that the endpoint cannot be reached.\n", [
      '@endpoint_name' => $endpoint_name,
      '@endpoint_url' => $endpoint_url,
    ]);

    // Give a generic error for all other responses.
  }
  else {
    return $this
      ->t("@endpoint_name (@endpoint_url) received a @status_code response. Please ensure a 200 response is sent.\n", [
      '@endpoint_name' => $endpoint_name,
      '@endpoint_url' => $endpoint_url,
      '@status_code' => $status_code,
    ]);
  }
}