Skip to content

Commit 64e842e

Browse files
committed
Add more details for exceptions to beta
1 parent 6719b84 commit 64e842e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Foxy/FoxyClient/FoxyClient.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ private function go($method, $uri, $post, $is_retry = false)
255255
return $this->processRequest($method, $uri, $post, $guzzle_args, $is_retry);
256256
//Catch Errors - http error
257257
} catch (\GuzzleHttp\Exception\RequestException $e) {
258-
return array("error_description" => $e->getMessage());
258+
return $this->handleException($e);
259259
//Catch Errors - not JSON
260260
} catch (\GuzzleHttp\Exception\ParseException $e) {
261-
return array("error_description" => $e->getMessage());
261+
return $this->handleException($e);
262262
}
263263
}
264264
}
@@ -355,6 +355,24 @@ public function getLinks()
355355
return $links;
356356
}
357357

358+
private function handleException(\Exception $e)
359+
{
360+
$error = array(
361+
"error_description" => $e->getMessage()
362+
);
363+
364+
if ($e->hasResponse()) {
365+
$response = $e->getResponse();
366+
$error = array_merge($error, array(
367+
"error_code" => $response->getStatusCode(),
368+
"response" => (string)$response,
369+
"error_contents" => (string) $response->getBody()->getContents()
370+
));
371+
}
372+
373+
return $error;
374+
}
375+
358376
//Return any errors that exist in the response data.
359377
public function getErrors($data)
360378
{

0 commit comments

Comments
 (0)