From 18a641ca8772b524370a2ef950ea743c7fffd206 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Tue, 19 Apr 2016 13:04:54 +0000 Subject: [PATCH] route : if there is an error with the ratelimiter (directory not writeable...), averload the exception by the ratelimiter exception git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2699 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- route.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/route.php b/route.php index 34273da..f741dd3 100644 --- a/route.php +++ b/route.php @@ -507,22 +507,32 @@ class route $ipClient = $_SERVER["REMOTE_ADDR"]; elseif (defined ("PHPUNIT")) $ipClient = "CLI"; - if ($this->ratelimiter !== null && $ipClient !== null && - $this->ratelimiter->set ("error-$ipClient") === false) + try { - $getCode = 406; - $message = dgettext("domframework", "Too much error requests"); - } - else - { - if ($e->getCode () === "" || $e->getCode () === 0) - $getCode = 500; + if ($this->ratelimiter !== null && $ipClient !== null && + $this->ratelimiter->set ("error-$ipClient") === false) + { + $getCode = 406; + $message = dgettext("domframework", "Too much error requests"); + } else - $getCode = $e->getCode (); + { + if ($e->getCode () === "" || $e->getCode () === 0) + $getCode = 500; + else + $getCode = $e->getCode (); + $message = $e->getMessage (); + if ($e->getCode () === 0) + $message .= "

The Exception code was 0 and converted to 500

\n"; + } + } + catch (Exception $e) + { + // If there is an error with the ratelimiter (file not writeable...), + // overload the Exception $message = $e->getMessage (); - if ($e->getCode () === 0) - $message .= "

The Exception code was 0 and converted to 500

\n"; + $getCode = $e->getCode (); } // If an error class/method is defined, use it in place of the default