From eaa7d6fafafe843c44bcfb6ba909ee4353a1af54 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 14 Nov 2022 11:12:35 +1300 Subject: convert HttpCodeException to an interface convert HttpCodeException to an interface --- core/Http/BadRequestException.php | 5 +++-- core/Http/HttpCodeException.php | 6 +++++- core/NoAccessException.php | 4 ++-- plugins/Login/Login.php | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/Http/BadRequestException.php b/core/Http/BadRequestException.php index 5f5bb69d74..bbc6472b94 100644 --- a/core/Http/BadRequestException.php +++ b/core/Http/BadRequestException.php @@ -8,11 +8,12 @@ namespace Piwik\Http; +use Piwik\NoAccessException; -class BadRequestException extends HttpCodeException +class BadRequestException extends NoAccessException { public function __construct($message) { parent::__construct($message, $code = 400); } -} \ No newline at end of file +} diff --git a/core/Http/HttpCodeException.php b/core/Http/HttpCodeException.php index f1d826f62a..4b7f9bc66c 100644 --- a/core/Http/HttpCodeException.php +++ b/core/Http/HttpCodeException.php @@ -7,7 +7,11 @@ */ namespace Piwik\Http; +use Throwable; -class HttpCodeException extends \Exception +interface HttpCodeException extends Throwable { + } + + diff --git a/core/NoAccessException.php b/core/NoAccessException.php index f0b9711edd..9136e2e8f1 100644 --- a/core/NoAccessException.php +++ b/core/NoAccessException.php @@ -9,6 +9,7 @@ namespace Piwik; +use Piwik\Exception\Exception; use Piwik\Http\HttpCodeException; /** @@ -16,9 +17,8 @@ use Piwik\Http\HttpCodeException; * * @api */ -class NoAccessException extends HttpCodeException +class NoAccessException extends Exception implements HttpCodeException { - private $isHtmlMessage = false; public function __construct($message) { diff --git a/plugins/Login/Login.php b/plugins/Login/Login.php index 2bf97938ff..55e3236e71 100644 --- a/plugins/Login/Login.php +++ b/plugins/Login/Login.php @@ -14,8 +14,8 @@ use Piwik\Common; use Piwik\Config; use Piwik\Container\StaticContainer; use Piwik\FrontController; -use Piwik\Http\HttpCodeException; use Piwik\IP; +use Piwik\NoAccessException; use Piwik\Piwik; use Piwik\Plugins\Login\Security\BruteForceDetection; use Piwik\Session; @@ -153,7 +153,7 @@ class Login extends \Piwik\Plugin /** @var BruteForceDetection $bruteForce */ $bruteForce = StaticContainer::get('Piwik\Plugins\Login\Security\BruteForceDetection'); if (!$this->hasPerformedBruteForceCheckForUserPwdLogin && $bruteForce->isEnabled() && $bruteForce->isUserLoginBlocked($login)) { - $ex = new HttpCodeException(Piwik::translate('Login_LoginNotAllowedBecauseUserLoginBlocked'), 403); + $ex = new NoAccessException(Piwik::translate('Login_LoginNotAllowedBecauseUserLoginBlocked'), 403); throw $ex; } // for performance reasons we make sure to execute it only once per request -- cgit v1.2.3