From ac6847045c0e78dcbb663232fabcd2a8ec7bab60 Mon Sep 17 00:00:00 2001 From: teromene Date: Wed, 4 Apr 2018 19:02:40 +0100 Subject: [PATCH] Catch Errors in order to display a message in more cases. We also catch Exceptions to maintain compat with php 5. Add check for simplexml extension. --- index.php | 18 +++++++++++++++--- lib/Exceptions.php | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 97a7645..af1ec7d 100644 --- a/index.php +++ b/index.php @@ -77,6 +77,9 @@ if(!extension_loaded('libxml')) if(!extension_loaded('mbstring')) die('"mbstring" extension not loaded. Please check "php.ini"'); +if(!extension_loaded('simplexml')) + die('"simplexml" extension not loaded. Please check "php.ini"'); + // configuration checks if(ini_get('allow_url_fopen') !== "1") die('"allow_url_fopen" is not set to "1". Please check "php.ini'); @@ -199,10 +202,14 @@ try { $bridge->setCache($cache); $bridge->setCacheTimeout($cache_timeout); $bridge->setDatas($params); - } catch(Exception $e) { + } catch(Error $e) { http_response_code($e->getCode()); header('Content-Type: text/html'); die(buildBridgeException($e, $bridge)); + } catch(Exception $e) { + http_response_code($e->getCode()); + header('Content-Type: text/html'); + die(buildBridgeException($e, $bridge)); } // Data transformation @@ -211,11 +218,16 @@ try { $format->setItems($bridge->getItems()); $format->setExtraInfos($bridge->getExtraInfos()); $format->display(); - } catch(Exception $e) { + } catch(Error $e) { http_response_code($e->getCode()); header('Content-Type: text/html'); die(buildTransformException($e, $bridge)); - } + } catch(Exception $e) { + http_response_code($e->getCode()); + header('Content-Type: text/html'); + die(buildBridgeException($e, $bridge)); + } + die; } diff --git a/lib/Exceptions.php b/lib/Exceptions.php index 252d1e3..02d63f1 100644 --- a/lib/Exceptions.php +++ b/lib/Exceptions.php @@ -54,7 +54,7 @@ function buildGitHubIssueQuery($title, $body, $labels = null, $maintainer = null * provided parameter are invalid */ function buildBridgeException($e, $bridge){ - if(!($e instanceof \Exception) || !($bridge instanceof \BridgeInterface)) { + if(( !($e instanceof \Exception) && !($e instanceof \Error)) || !($bridge instanceof \BridgeInterface)) { return null; } @@ -85,7 +85,7 @@ unable to receive or process the remote website's content!"; * provided parameter are invalid */ function buildTransformException($e, $bridge){ - if(!($e instanceof \Exception) || !($bridge instanceof \BridgeInterface)) { + if(( !($e instanceof \Exception) && !($e instanceof \Error)) || !($bridge instanceof \BridgeInterface)) { return null; }