从平衡获取HTTP响应

时间:2014-03-25 00:44:52

标签: rest balanced-payments

如果我使用的是PHP代码,例如

$card = Balanced\Card::get("/v1/marketplaces/TEST-MP4K6K0PWGyPtXL4LZ42sQSb/cards/CC5N3HHUDrAyvhNwQOoUd3UX");
$card->unstore();

$customer->addCard($card)

如何从平衡读取HTTP响应以了解它是否有效或错误是什么?

1 个答案:

答案 0 :(得分:3)

如果API中存在非2xx HTTP响应,则平衡客户端库为written so that they will throw exceptions

判断addCard操作失败的正确方法是编写一些看起来像

的代码
try {
    $customer->addCard($card)
} catch (Balanced\Error $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}