Skip to content

Commit

Permalink
Merge pull request #291 from izhyvaiev/master
Browse files Browse the repository at this point in the history
Adding ability to get Recurly error code from Recurly_Error Exception
  • Loading branch information
drewish authored Jan 6, 2017
2 parents 102e093 + c074043 commit a3b7a68
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 16 additions & 1 deletion lib/recurly/errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a3b7a68

Please sign in to comment.