Recurly PHP client. How to customize error messages? -
i'm trying customize error messages. handling errors used "try/catch" block according this recurly documentation, example:
try { $account = recurly_account::get('my_account_id'); $subscription = new recurly_subscription(); $subscription->account = $account; $subscription->plan_code = 'my_plan_code'; $subscription->coupon_code = 'my_coupon_code'; /* .. etc .. */ $subscription->create(); } catch (exception $e) { $errormsg = $e->getmessage(); print $errormsg; }
i wanted use code in catch block this:
catch (exception $e) { $errorcode = $e->getcode(); print $myerrormsg[$errorcode]; // array of custom messages. }
but getcode() method returns 0 possible errors.
my question recurly team (or there in theme): how error code errors? or please explain me how can resolve topic. thanks!
if @ php client on github , search "throw new" done when exception thrown you'll see don't set exception error code second parameter of exception constructor method.
recurly php client on github: https://github.com/recurly/recurly-client-php/search?utf8=%e2%9c%93&q=throw+new
php exception documentation: http://php.net/manual/en/language.exceptions.extending.php
therefore, you'll either need catch more exceptions based on name i.e.
catch (recurly_notfounderror $e) { print 'record not found'; }
or
look @ exception message , compare
catch (exception $e) { $errormessage = $e->getmessage(); if($errormessage=='coupon not redeemable.') { $myerrorcode=1; } //add more else if, or case switch statement handle various errors want handle print $myerrormsg[$myerrorcode]; // array of custom messages. }
Comments
Post a Comment