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
pull/184/head
iglocska 2024-08-29 06:49:28 +02:00
parent 4906cae0c7
commit 33c5c8a9d9
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 5 additions and 0 deletions

View File

@ -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;