Last active
December 26, 2015 12:39
-
-
Save craigtaub/7152757 to your computer and use it in GitHub Desktop.
This file contains 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
get() could include try/catch. | |
Inside would fetch from iBL and parse response. | |
Parse can throw errors from each errored process inside _parseResponse(). | |
Remove handleErrors() and _getIblError, add _parseResponse(). | |
Response is moved to instance var (debatable, would give object a state). | |
checkJsonError does not throw anything unless finds an error. | |
Below an example, not complete: | |
private function _parseResponse() { | |
$body = $this->_fetchBody(); | |
$json = $this->_parseJsonBody($body); | |
$this->_checkForJsonError($json); | |
} | |
_private function _checkForJsonError($json) { | |
if (isset($json->error, $json->error->details)) { | |
$message = isset($json->error->id) | |
? sprintf("[%s] %s", $json->error->id, $json->error->details) | |
: $json->error->details; | |
throw BBC_Service_Bamboo_Exception_JsonError($message); | |
} | |
} | |
_private function _fetchBody() { | |
$body = $this->_response->getBody(); | |
if (!$body) { | |
throw BBC_Service_Bamboo_Exception_NoBodyContent; | |
} | |
return $body; | |
} | |
_private function _parseJsonBody($body) { | |
try { | |
return json_decode($body); | |
} catch (Exception $e) { | |
throw BBC_Service_Bamboo_Exception_JsonParseError($e); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment