You are here

public function AcquiaLiftAPI::handleBadResponse in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 includes/acquia_lift.classes.inc \AcquiaLiftAPI::handleBadResponse()

Figures out the correct exception to throw and throws it.

Parameters

$response_code: The response code, e.g. 404.

$fail_msg: The message to use for the exception, and for logging if $log_failure it TRUE.

array $vars: Variables to pass to the message.

bool $log_failure: Whether failures should be logged or not

bool $soft_fail: Whether to fail softly, i.e. without throwing an exception.

4 calls to AcquiaLiftAPI::handleBadResponse()
AcquiaLiftAPI::makeDeleteRequest in includes/AcquiaLiftAPI.inc
Makes an Acquia Authenticated DELETE request to an API endpoint.
AcquiaLiftAPI::makeGetRequest in includes/AcquiaLiftAPI.inc
Makes an Acquia Authenticated GET request to an API endpoint.
AcquiaLiftAPI::makePostRequest in includes/AcquiaLiftAPI.inc
Makes an Acquia Authenticated POST request to an API endpoint.
AcquiaLiftAPI::makePutRequest in includes/AcquiaLiftAPI.inc
Makes an Acquia Authenticated PUT request to an API endpoint.

File

includes/AcquiaLiftAPI.inc, line 987

Class

AcquiaLiftAPI

Code

public function handleBadResponse($response_code, $fail_msg, $vars = array(), $log_failure = TRUE, $soft_fail = FALSE) {
  if ($exception_class = self::mapBadResponseToExceptionClass($response_code)) {
    if ($log_failure) {
      $logger = $this
        ->logger();
      $logger
        ->log(PersonalizeLogLevel::ERROR, $fail_msg, $vars);
    }
    if (!$soft_fail) {
      throw new $exception_class(t($fail_msg, $vars));
    }
  }
  if (self::isSuccessful($response_code)) {

    // If the response wasn't actually bad but we still got here somehow, just
    // log a warning and return.
    if ($log_failure) {
      $this
        ->logger()
        ->log(PersonalizeLogLevel::WARNING, $fail_msg, $vars);
    }
    return;
  }
  if (!$soft_fail) {

    // Otherwise throw a generic exception.
    throw new AcquiaLiftException(t($fail_msg, $vars));
  }
}