Skip to content

Commit

Permalink
Add better error messages to OAuth token requests
Browse files Browse the repository at this point in the history
  • Loading branch information
szeber committed Sep 19, 2016
1 parent da5d35a commit 806927f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ShoppinPal/Vend/Auth/OAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 806927f

Please sign in to comment.