Created
June 1, 2017 10:46
-
-
Save teklakct/610051131a4b9b611e722fea4453d376 to your computer and use it in GitHub Desktop.
GuzzleRequestExceptionHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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