From a26d00530ce568136f7ae7281181693da316ba13 Mon Sep 17 00:00:00 2001 From: Nick Daugherty <ndaugherty987@gmail.com> Date: Tue, 23 Apr 2013 17:44:03 -0600 Subject: [PATCH] Overloaded __call() to transparently handle Exceptions in production Most Exceptions are thrown from API timeouts - which are more difficult to find in testing. To prevent fatals in production, this transparently handles Exceptions in __call(), returning an empty array instead. Room for improvement - store the Exception information as a WP_Error in a protected var. - Determine what the expected response type is. For example, status updates don't expect an array response - an appropriate response should be returned for the request. --- class-wp-codebird.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/class-wp-codebird.php b/class-wp-codebird.php index 6f593b4..04c13ad 100644 --- a/class-wp-codebird.php +++ b/class-wp-codebird.php @@ -31,6 +31,20 @@ class WP_Codebird extends Codebird { return self::$_instance; } + /** + * Overload magic __call() to transparently intercept Exceptions + * + * Most exceptions encountered in production are API timeouts - this will + * transparently handle these Exceptions to prevent fatal errors + */ + public function __call( $function, $arguments ) { + try { + return parent::__call( $function, $arguments ); + } catch ( Exception $e ) { + return array(); + } + } + /** * Calls the API using Wordpress' HTTP API. * -- GitLab