From 33c5c8a9d98e06ee2c7d1c166c54d32b6b79e8d0 Mon Sep 17 00:00:00 2001 From: iglocska Date: Thu, 29 Aug 2024 06:49:28 +0200 Subject: [PATCH] fix: [error messages] improved for empty/malformed request bodies - instead of failing on a validation level for empty data, fail immediately on CRUD component level - send a clear message to the user that the request was malformed / the proper media type headers were not set --- src/Controller/Component/CRUDComponent.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index 02e3acb..9660d58 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -15,8 +15,10 @@ use Cake\Database\Expression\QueryExpression; use Cake\Routing\Router; use Cake\Http\Exception\MethodNotAllowedException; use Cake\Http\Exception\NotFoundException; +use Cake\Http\Exception\BadRequestException; use Cake\Collection\Collection; use App\Utility\UI\IndexSetting; +use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag; class CRUDComponent extends Component { @@ -703,6 +705,9 @@ class CRUDComponent extends Component private function __massageInput($params) { $input = $this->request->getData(); + if (empty($input)) { + throw new BadRequestException(__('Invalid request content. Please make sure that you pass the data to be handled in the body and that the proper Accept and Content-type headers are set. This could also be caused by invalid JSON data being passed.')); + } if (!empty($params['override'])) { foreach ($params['override'] as $field => $value) { $input[$field] = $value;