APIから消費するためにGuzzleを使用しています。その 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();
}
そうすることを可能にする方法はありますか?