Skip to content

Commit

Permalink
Merge 124003f into 0e7b21c
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota committed Jun 29, 2020
2 parents 0e7b21c + 124003f commit fec704e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Listener/JsonApiListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -790,25 +791,23 @@ 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) {
throw new BadRequestException(
'JSON API requests with data require the "' . self::MIME_TYPE . '" Content-Type header'
);
}

return true;
}

/**
Expand Down

0 comments on commit fec704e

Please sign in to comment.