【发布时间】:2013-03-22 01:11:48
【问题描述】:
我在 PHP 中使用 GoCardless's API 版本来处理我网站上的付款。但是,当他们的 API 返回错误时,我想向用户显示更有效的错误。
我已经完成了一半,但我想知道我是否可以做以下事情:
如果我有以下错误:
Array([error] => Array([0] =>资源已经确认))
有没有办法只用 PHP 提取 The resource has already been confirmed 部分?
我的代码:
try{
$confirmed_resource = GoCardless::confirm_resource($confirm_params);
}catch(GoCardless_ApiException $e){
$err = 1;
print '<h2>Payment Error</h2>
<p>Server Returned : <code>' . $e->getMessage() . '</code></p>';
}
谢谢。
更新 1:
触发异常的代码:
$http_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_response_code < 200 || $http_response_code > 300) {
// Create a string
$message = print_r(json_decode($result, true), true);
// Throw an exception with the error message
throw new GoCardless_ApiException($message, $http_response_code);
}
更新 2 :-> print_r($e->getMessage()) 输出:
Array([error] => Array([0] =>资源已经确认))
【问题讨论】:
-
$errorArray['error'][0]
标签: php arrays exception gocardless