Skip to content

Commit 08c5f1f

Browse files
committed
Merge pull request #94 from delatbabel/handle-guzzle-exceptions
Adding exception handler, mostly for catching guzzle errors
2 parents 613f6ee + c5338e7 commit 08c5f1f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Message/AbstractRestRequest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
namespace Omnipay\PayPal\Message;
77

8+
use Omnipay\Common\Exception\InvalidResponseException;
9+
810
/**
911
* PayPal Abstract REST Request
1012
*
@@ -160,9 +162,15 @@ function ($event) {
160162
// logging engine is being used.
161163
// echo "Data == " . json_encode($data) . "\n";
162164

163-
$httpResponse = $httpRequest->send();
164-
165-
return $this->response = $this->createResponse($httpResponse->json(), $httpResponse->getStatusCode());
165+
try {
166+
$httpResponse = $httpRequest->send();
167+
return $this->response = $this->createResponse($httpResponse->json(), $httpResponse->getStatusCode());
168+
} catch (\Exception $e) {
169+
throw new InvalidResponseException(
170+
'Error communicating with payment gateway: ' . $e->getMessage(),
171+
$e->getCode()
172+
);
173+
}
166174
}
167175

168176
/**

0 commit comments

Comments
 (0)