Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guzzle 5 - Get Response Body on ServerException

Tags:

php

guzzle

I am using Guzzle (latest 5.2) to do a POST call to a server. The API on this server returns a "HTTP/1.1 500 Internal Server Error" response, but also returns a body. How do I get access to the body of the response from the exception?

Below is what I get when I do the POST with curl -v:

* upload completely sent off: 826 out of 826 bytes
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 24 Feb 2015 01:57:10 GMT
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Content-Type: application/xml
< Content-Length: 154
< Connection: close
<
* Closing connection 0
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><addressList xmlns:ns2="http://addresslistserver.c2m.com/"><status>9</status><lists/></addressList>
like image 936
Joel D Avatar asked Mar 16 '23 22:03

Joel D


1 Answers

I've discovered a solution:

$exception->getResponse()->getBody()

Could have sworn I tried that hours ago and it didn't work, but I guess not.

like image 109
Joel D Avatar answered Mar 29 '23 19:03

Joel D