Handle Guzzle exception and get HTTP body

前端 未结 6 678
长发绾君心
长发绾君心 2020-12-07 08:32

I would like to handle errors from Guzzle when the server returns 4xx and 5xx status codes. I make a request like this:

$client = $this->getGuzzleClient()         


        
6条回答
  •  抹茶落季
    2020-12-07 08:45

    if put 'http_errors' => false in guzzle request options, then it would stop throw exception while get 4xx or 5xx error, like this: $client->get(url, ['http_errors' => false]). then you parse the response, not matter it's ok or error, it would be in the response for more info

提交回复
热议问题