diff --git a/src/Listener/JsonApiListener.php b/src/Listener/JsonApiListener.php index 30c2b5c3..90e91310 100644 --- a/src/Listener/JsonApiListener.php +++ b/src/Listener/JsonApiListener.php @@ -10,6 +10,7 @@ use Cake\Datasource\ResultSetInterface; use Cake\Event\EventInterface; use Cake\Http\Exception\BadRequestException; +use Cake\Http\Exception\MethodNotAllowedException; use Cake\Http\Response; use Cake\ORM\Association; use Cake\ORM\Query; @@ -790,16 +791,16 @@ protected function _validateConfigOptions(): void * Override ApiListener method to enforce required JSON API request methods. * * @throws \Cake\Http\Exception\BadRequestException - * @return bool + * @return void */ - protected function _checkRequestMethods(): bool + protected function _checkRequestMethods(): void { if ($this->_request()->is('put')) { - throw new BadRequestException('JSON API does not support the PUT method, use PATCH instead'); + throw new MethodNotAllowedException('JSON API does not support the PUT method, use PATCH instead'); } if (!$this->_request()->contentType()) { - return true; + return; } if ($this->_request()->contentType() !== self::MIME_TYPE) { @@ -807,8 +808,6 @@ protected function _checkRequestMethods(): bool 'JSON API requests with data require the "' . self::MIME_TYPE . '" Content-Type header' ); } - - return true; } /**