Skip to content

Commit

Permalink
Catch guzzle ClientException
Browse files Browse the repository at this point in the history
  • Loading branch information
Frantisek Sichinger committed Nov 2, 2017
1 parent a7b1b60 commit be503f5
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Http/JsonBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GoPay\Http\Log\Logger;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\ClientException;

class JsonBrowser
{
Expand Down Expand Up @@ -32,11 +33,23 @@ public function send(Request $r)
$response = new Response((string) $guzzResponse->getBody());
$response->statusCode = (string) $guzzResponse->getStatusCode();
$response->json = json_decode((string) $response, true);
} catch (\Exception $e) {
$response = new Response($e->getMessage());
$response->statusCode = 500;
}
$this->logger->logHttpCommunication($r, $response);
return $response;
} catch (ClientException $e) {
if ($e->hasResponse()) {
$response = new Response($e->getResponse()->getBody());
$response->json = json_decode($e->getResponse()->getBody());
$response->status_code = $e->getCode();
$this->logger->logHttpCommunication($r, $response);
return $response;
}
} catch (\Exception $ex) {
$response = new Response($ex->getMessage());
$response->status_code = 500;
$this->logger->logHttpCommunication($r, $response);
return $response;
}

}

}

0 comments on commit be503f5

Please sign in to comment.