Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed the error handling for connection errors to use PhealConnecti…

…onException instead of PhealException.

Usually you'd want to do "other stuff" for Connection errors then General errors.
  • Loading branch information...
commit 4b5abaee5a7a093ce6e421fe40f4b97689b6dbbb 1 parent 7d57c09
Cyerus Cyerus authored
Showing with 44 additions and 4 deletions.
  1. +7 −4 Pheal.php
  2. +33 −0 PhealConnectionException.php
  3. +4 −0 README.md
11 Pheal.php
View
@@ -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);
@@ -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;
}
@@ -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 {
33 PhealConnectionException.php
View
@@ -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 Exception
+{
+
+}
4 README.md
View
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.