From 160ea78deaa97becf2e3a809284bcd03c5c1d3f3 Mon Sep 17 00:00:00 2001 From: antonis Date: Tue, 8 May 2018 16:08:14 +0300 Subject: [PATCH] resolve #12 catch error and add message to response --- src/Message/PurchaseRequest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index ddc5da0..47e65e1 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -30,6 +30,16 @@ public function sendData($data) { $httpResponse = $this->sendRequest('POST', '/buttons', $data); - return $this->response = new PurchaseResponse($this, $httpResponse->json()); + try{ + $jsonRes = $httpResponse->json(); + } + catch (\Error $e){ + $res = array(); + $res["error"] = $e->getMessage(); + + return $this->response = new PurchaseResponse($this, $res); + + } + return $this->response = new PurchaseResponse($this, $jsonRes); } }