Catching exceptions from Guzzle

前端 未结 8 1745
情歌与酒
情歌与酒 2020-11-30 22:07

I\'m trying to catch exceptions from a set of tests I\'m running on an API I\'m developing and I\'m using Guzzle to consume the API methods. I\'ve got the tests wrapped in a

相关标签:
8条回答
  • 2020-11-30 22:57

    I was catching GuzzleHttp\Exception\BadResponseException as @dado is suggesting. But one day I got GuzzleHttp\Exception\ConnectException when DNS for domain wasn't available. So my suggestion is - catch GuzzleHttp\Exception\ConnectException to be safe about DNS errors as well.

    0 讨论(0)
  • 2020-11-30 23:01

    Old question, but Guzzle adds the response within the exception object. So a simple try-catch on GuzzleHttp\Exception\ClientException and then using getResponse on that exception to see what 400-level error and continuing from there.

    0 讨论(0)
提交回复
热议问题