Skip to content

Instantly share code, notes, and snippets.

@teklakct
Created June 1, 2017 10:46
Show Gist options
  • Save teklakct/610051131a4b9b611e722fea4453d376 to your computer and use it in GitHub Desktop.
Save teklakct/610051131a4b9b611e722fea4453d376 to your computer and use it in GitHub Desktop.
GuzzleRequestExceptionHandler
<?php
private function exceptionHandler(GuzzleRequestException $e)
{
if ($e->hasResponse()) {
if ($e->getResponse()->getStatusCode() >= 500) {
throw $e;
}
$error = json_decode($e->getResponse()->getBody()->getContents(), true);
if (isset($error['errors'])) {
switch (array_shift($error['errors'])['code']) {
case 'email_already_taken':
throw RequestException::userAlreadyExist();
default:
throw RequestException::unknownError();
}
}
}
throw $e;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment