8p / EightPointsGuzzleBundle

⛽️ Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony
MIT License
440 stars 71 forks source link

Handling exceptions in 6.0 #117

Closed BoShurik closed 7 years ago

BoShurik commented 7 years ago

This code

try {
    $httpResponse = $this->httpClient->sendRequest($httpRequest);
} catch (HttpException $exception) {
    throw ExceptionHandler::handle($exception);
}

no longer catch an 401 exception (may be other exceptions too) The problem is in this commit by @thomasjohansen

florianpreusner commented 7 years ago

Thanks for your report. 5.4 was removed a couple of days ago. Are you sure that you are using this version? We have this "feature" in v6.0. So maybe the title should be changed.

BoShurik commented 7 years ago

Just update to 5.4 version https://packagist.org/packages/eightpoints/guzzle-bundle

BoShurik commented 7 years ago

In 6.0 the problem still exists

florianpreusner commented 7 years ago

Mhhh, I removed this version from packagist, but when clicking update it will be reactivated, strange. Sorry for the trouble. I will take a look into this later today.

BoShurik commented 7 years ago

@florianpreusner looks like you must remove it from releases

florianpreusner commented 7 years ago

@BoShurik I can' reproduce your issue. "sendRequest" is a method provided by your own class, or? Inside you are using \GuzzleHttp\Client->request()?

When I'm getting a 401 I get the exception (GuzzleHttp\Exception\ClientException) and can catch it. That works with the modification by @thomasjohansen and also without. So I can't see a change in the behavior. Maybe you should adjust your class that will be catched. I can't see a place where "HttpException" will be thrown.

$client = $this->get('guzzle.client.test_client');        
try {
    $response = $client->request('GET', 'https://httpbin.org/status/401');
} catch(\GuzzleHttp\Exception\ClientException $e) {
    // here we go
}
BoShurik commented 7 years ago

Forgot to mention that I use httplug and php-http/guzzle6-adapter HttpException is Http\Client\Exception\HttpException

TheLevti commented 7 years ago

Can it be that my latest PR #115 fixed this issue (see #114)? I had the same problem of not getting an exception. Try to use the master branch.

BoShurik commented 7 years ago

It works! Can you add tag?

florianpreusner commented 7 years ago

Just released v6.0.1 https://github.com/8p/GuzzleBundle/releases/tag/v6.0.1