0

I make a Guzzle 6 request, and this request responses with a 401.

$client = new Client();
$response = $client->request('GET', .... 
....

My Script will stop then and will return a error message.

GuzzleHttp \ Exception \ ClientException (401) Client error: GET https://.....?lang=de resulted in a 401 Unauthorized response: Unauthorized

Try catch does not work.

How can I intercept the error message?

Thanks for help!

Mondy
  • 2,055
  • 4
  • 19
  • 29
  • 1
    Does this answer your question? [Catching exceptions from Guzzle](https://stackoverflow.com/questions/17658283/catching-exceptions-from-guzzle) – Arif Jun 16 '20 at 11:52

2 Answers2

3

I found the error. I have added the parameter

'http_errors' => false

http://docs.guzzlephp.org/en/stable/request-options.html#http-errors

Now I can check the response status:

if ($response->getStatusCode() != 200) {
    echo "error";
}
Mondy
  • 2,055
  • 4
  • 19
  • 29
0

We need more code to help you, which parameters you use, what is your request, etc ...

You can try to send your request with Postman to check if your parameter are correcly sended

Jonathan Delean
  • 1,011
  • 1
  • 8
  • 25
  • Postman Status gets "401 Unauthorized" and RAW Body is: Unauthorized My Problem is, that the Script aborts with an error message after sending the request. But I don't want, that the script aborts. So there should be a possibility to catch this 401 response. – Mondy Jun 16 '20 at 10:34