From c0740432087f6b0a843f9bebe4dbf98a5c5a8888 Mon Sep 17 00:00:00 2001 From: izhyvaiev Date: Tue, 20 Dec 2016 15:16:25 +0200 Subject: [PATCH] Adding ability to get Recurly error code from Recurly_Error Exception --- lib/recurly/errors.php | 17 ++++++++++++++++- lib/recurly/response.php | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/recurly/errors.php b/lib/recurly/errors.php index 8d4335f2..01c9ba1c 100644 --- a/lib/recurly/errors.php +++ b/lib/recurly/errors.php @@ -7,7 +7,22 @@ * @package Recurly_Client_PHP * @copyright Copyright (c) 2011 {@link http://recurly.com Recurly, Inc.} */ -class Recurly_Error extends Exception {} +class Recurly_Error extends Exception { + + private $recurlyCode; + + public function __construct($message, $code = 0, Exception $previous = null, $recurlyCode = null) + { + $this->recurlyCode = $recurlyCode; + + parent::__construct($message, $code, $previous); + } + + public function getRecurlyCode() + { + return $this->recurlyCode; + } +} class Recurly_NotFoundError extends Recurly_Error {} diff --git a/lib/recurly/response.php b/lib/recurly/response.php index 5bc8f74c..d4817bf2 100644 --- a/lib/recurly/response.php +++ b/lib/recurly/response.php @@ -49,7 +49,8 @@ public function assertValidResponse() throw new Recurly_ConnectionError('An error occurred while connecting to Recurly.'); case 400: $message = (is_null($error) ? 'Bad API Request' : $error->description); - throw new Recurly_Error($message); + $recurlyCode = (is_null($error) ? null : $error->symbol); + throw new Recurly_Error($message, 0, null, $recurlyCode); case 401: throw new Recurly_UnauthorizedError('Your API Key is not authorized to connect to Recurly.'); case 403: