0
votes

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!

2
Does this answer your question? Catching exceptions from Guzzle - Arif

2 Answers

1
votes

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";
}
0
votes

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