Skip to content
Shabab Haider Siddique edited this page May 25, 2021 · 2 revisions

Exception

namespace Cardinity\Exception

Exception objects are used to identify problems when they occur.

Available exception classes

Class Code Message / Description
Declined 402 Request Failed – Your request was valid but it was declined
Forbidden 403 Forbidden – You do not have access to this resource.
InternalServerError 500 Internal Server Error – We had a problem on our end. Try again later.
InvalidAttributeValue Violations: List of violations
MethodNotAllowed 405 Method Not Allowed – You tried to access a resource using an invalid HTTP method.
NotAcceptable 406 Not Acceptable – Wrong Accept headers sent in the request.
NotFound 404 Not Found – The specified resource could not be found.
RequestTimeout 0
ServiceUnavailable 503 Service Unavailable – We’re temporarily off-line for maintenance. Please try again later.
Unauthorized 401 Unauthorized – Your authorization information was missing or wrong.
ValidationFailed 400 Bad Request – Your request contains field or business logic validation errors or provided JSON is malformed.

Example

Full list of Exception catch

<?php

try {
  $payment = $client->call($method);
} catch (Cardinity\Exception\InvalidAttributeValue $exception $e) {
  foreach ($exception->getViolations() as $key => $violation) {
      array_push($errors, $violation->getPropertyPath() . ' ' . $violation->getMessage());
  }
} catch (Cardinity\Exception\ValidationFailed $exception) {
  foreach ($exception->getErrors() as $key => $error) {
      array_push($errors, $error['message']);
  }
} catch (Cardinity\Exception\Declined $exception) {
  foreach ($exception->getErrors() as $key => $error) {
      array_push($errors, $error['message']);
  }
} catch (Cardinity\Exception\NotFound $exception) {
  foreach ($exception->getErrors() as $key => $error) {
      array_push($errors, $error['message']);
  }
} catch (Cardinity\Exception\NotAcceptable $exception) {
  foreach ($exception->getErrors() as $key => $error) {
      array_push($errors, $error['message']);
  }
} catch (Cardinity\Exception\Forbidden $exception) {
  foreach ($exception->getErrors() as $key => $error) {
      array_push($errors, $error['message']);
  }
} catch (Cardinity\Exception\InternalServerError $exception) {
  foreach ($exception->getErrors() as $key => $error) {
      array_push($errors, $error['message']);
  }
} catch (Cardinity\Exception\MethodNotAllowed $exception) {
  foreach ($exception->getErrors() as $key => $error) {
      array_push($errors, $error['message']);
  }
} catch (Cardinity\Exception\ServiceUnavailable $exception) {
  foreach ($exception->getErrors() as $key => $error) {
      array_push($errors, $error['message']);
  }
} catch (Cardinity\Exception\Unauthorized $exception) {
  foreach ($exception->getErrors() as $key => $error) {
      array_push($errors, $error['message']);
  }
} catch (Exception $exception) {
  $errors = [
      $exception->getMessage(),
      //$exception->getPrevious()->getMessage()
  ];
}

Clone this wiki locally