From c6346e80df49733c6734d2fa510de27e383030c5 Mon Sep 17 00:00:00 2001 From: Joshua Chamberlain Date: Mon, 15 Sep 2014 16:01:24 -0700 Subject: [PATCH] Return non-JSON response data --- src/Mailgun/Connection/RestClient.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index 88bd574..3fcdaa0 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -117,9 +117,11 @@ class RestClient{ public function responseHandler($responseObj){ $httpResponseCode = $responseObj->getStatusCode(); if($httpResponseCode === 200){ - $jsonResponseData = json_decode($responseObj->getBody(), false); + $data = (string) $responseObj->getBody(); + $jsonResponseData = json_decode($data, false); $result = new \stdClass(); - $result->http_response_body = $jsonResponseData; + // return response data as json if possible, raw if not + $result->http_response_body = $data && $jsonResponseData === null ? $data : $jsonResponseData; } elseif($httpResponseCode == 400){ throw new MissingRequiredParameters(EXCEPTION_MISSING_REQUIRED_PARAMETERS);