Skip to content
This repository has been archived by the owner on Apr 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #30 from Cyerus/master
Browse files Browse the repository at this point in the history
PhealConnectionException introduction / suggestion
  • Loading branch information
ppetermann committed Nov 18, 2012
2 parents 7d57c09 + 60812d1 commit e1c5baf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Pheal.php
Expand Up @@ -228,12 +228,15 @@ private function request_xml($scope, $name, array $opts = array())
// just forward HTTP Errors
} catch(PhealHTTPException $e) {
throw $e;

// just forward PhealConnectionException errors
} catch(PhealConnectionException $e) {
throw $e;
// other request errors
} catch(Exception $e) {
// log + throw error
PhealConfig::getInstance()->log->errorLog($scope,$name,$http_opts,$e->getCode() . ': ' . $e->getMessage());
throw new PhealException('API Date could not be read / parsed, original exception: ' . $e->getMessage());
// change Exception to PhealException but keep the original error data (easier debugging in client application).
throw new PhealException('Original exception: ' . $e->getMessage(), $e->getCode(), $e);
}
PhealConfig::getInstance()->cache->save($this->userid,$this->key,$scope,$name,$opts,$this->xml);

Expand Down Expand Up @@ -336,7 +339,7 @@ public static function request_http_curl($url,$opts)

// curl errors
if($errno)
throw new Exception($error, $errno);
throw new PhealConnectionException($error, $errno);
else
return $result;
}
Expand Down Expand Up @@ -407,7 +410,7 @@ public static function request_http_file($url,$opts)
// set track_errors back to the old value
ini_set('track_errors',$oldTrackErrors);

throw new Exception($message);
throw new PhealConnectionException($message);

// return result
} else {
Expand Down
33 changes: 33 additions & 0 deletions PhealConnectionException.php
@@ -0,0 +1,33 @@
<?php
/*
MIT License
Copyright (c) 2010 - 2012 Peter Petermann
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* Pheal Connection Exception, where connection problems will be dumped into for easy identifying
*/
class PhealConnectionException extends PhealException
{

}
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -226,6 +226,10 @@ Pheal will throw an PhealAccessException so you can react on the access limitati
} catch(PhealAPIException $e) {
echo 'api error: ' . $e->code . ' message: ' . $e->getMessage();
/* do something - example: disable key */

} catch(PhealConnectionException $e) {
echo 'connection error: ' . $e->code . ' message: ' . $e->getMessage();
/* do something - example: skip script, for instance EVE servers are down */

} catch(PhealException $e) {
echo 'generic error: ' . $e->code . ' message: ' . $e->getMessage();
Expand Down

0 comments on commit e1c5baf

Please sign in to comment.