【发布时间】:2014-05-28 21:35:48
【问题描述】:
我正在使用 Guzzle 从 API 中消费。 当该 API 中出现错误时,响应如下所示。
Status Code: 500
Content-Type: application/json
-----
{
error: 'identifier',
error_messsage: 'foo bar'
}
我希望该正文响应(json 编码)是 Guzzle 处理的异常中的消息。
try {
// Below, a Guzzle request
$request->send();
}
catch ( \Exception $e ) {
// returns the error response body we talked about before
$e->getMessage();
}
有没有办法做到这一点?
【问题讨论】:
-
您看到了吗:
getResponse以及关于 HTTP 错误的部分。 guzzle.readthedocs.org/en/latest/clients.html#error-handling我不知道你在问什么。
标签: php json error-handling response guzzle