Skip to content

Commit 1cbd682

Browse files
BVancea25michalkleinersgiehl
authored
Send response code 400 when requesting a non existing method (#22334)
* fixed 200 OK BUG * regex for error message matching * throwing an instace of HttpCodeException * Update core/Http/BadRequestException.php Co-authored-by: Michal Kleiner <mk@011.nz> * Update core/API/Proxy.php Co-authored-by: Michal Kleiner <mk@011.nz> * Apply suggestions from code review --------- Co-authored-by: Michal Kleiner <mk@011.nz> Co-authored-by: Stefan Giehl <stefan@matomo.org>
1 parent bebbd31 commit 1cbd682

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

ā€Žcore/API/Proxy.phpā€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Piwik\API;
1111

1212
use Exception;
13+
use Piwik\Http\BadRequestException;
1314
use Piwik\Common;
1415
use Piwik\Container\StaticContainer;
1516
use Piwik\Context;
@@ -615,7 +616,7 @@ private function loadMethodMetadata($class, $method)
615616
private function checkMethodExists($className, $methodName)
616617
{
617618
if (!$this->isMethodAvailable($className, $methodName)) {
618-
throw new Exception(Piwik::translate('General_ExceptionMethodNotFound', array($methodName, $className)));
619+
throw new BadRequestException(Piwik::translate('General_ExceptionMethodNotFound', [$methodName, $className]));
619620
}
620621
}
621622

ā€Žcore/Http/BadRequestException.phpā€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class BadRequestException extends \Exception implements HttpCodeException
1313
{
1414
public function __construct($message, $code = 400)
1515
{
16-
parent::__construct($message);
16+
parent::__construct($message, $code);
1717
}
1818
}

0 commit comments

Comments
Ā (0)
⚔