我正在尝试连接支付网关api。当我做以下
try {
$result = $transaction_api->charge($access_token,$request_body);
echo "success";
} catch (\someprogram\ApiException $e) {
echo"fail";
echo "<pre>";
print_r($e);
echo "</pre>";
}
当它失败时会抛出异常。 $ e将打印出以下内容
someprogram\ApiException Object
(
[responseBody:protected] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[category] => PAYMENT_METHOD_ERROR
[code] => VERIFY_CVV_FAILURE
[detail] => Card verification code check failed.
)
)
)
)
一般问题是如何访问$ e中的信息?有没有办法将异常转换为通用对象,就像json_decode()?
因为当我尝试执行print_r($e->responseBody->errors);
之类的操作时,我收到错误提示Cannot access protected property someprogram\ApiException::$responseBody
目标是根据错误重定向用户。