From 806927f95da2dd20360b217363dc53eaa02eab15 Mon Sep 17 00:00:00 2001 From: Zsolt Szeberenyi Date: Mon, 19 Sep 2016 23:18:29 +1200 Subject: [PATCH] Add better error messages to OAuth token requests --- src/ShoppinPal/Vend/Auth/OAuth.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ShoppinPal/Vend/Auth/OAuth.php b/src/ShoppinPal/Vend/Auth/OAuth.php index fa4307c..2408202 100644 --- a/src/ShoppinPal/Vend/Auth/OAuth.php +++ b/src/ShoppinPal/Vend/Auth/OAuth.php @@ -180,7 +180,18 @@ protected function sendVendTokenRequest($domainPrefix, array $params) $result = $request->send(); if (!$result->isRequestSuccessful()) { - throw new Exception('Error while sending the access token request.', 0, null, $result); + if ($result->getError()) { + $additionalInfo = 'Curl error: ' . $result->getError(); + } else { + $statusCode = $result->getResponseCode(); + preg_match( + '#^HTTP/[0-9\.]+ ' . (int)$statusCode . '[^\n]+#ms', + $result->getResponseHeaders(), + $matches + ); + $additionalInfo = 'Status line: ' . $matches[0]; + } + throw new Exception('Error while sending the access token request. ' . $additionalInfo, 0, null, $result); } $resultJson = json_decode($result->getResponseBody(), true);