Skip to content

Instantly share code, notes, and snippets.

@craigtaub
Last active December 26, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigtaub/7152757 to your computer and use it in GitHub Desktop.
Save craigtaub/7152757 to your computer and use it in GitHub Desktop.
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