I created my custom Controller for POST request, but i all time have empty response.
$testIds = $this->request->getPost('test');
$items = [];
foreach ($testIds as $id) {
$items[$id] = [
'test' => $id,
];
}
if (count($items)) {
$response = [
'success' => true,
'items' => $items
];
} else {
$response = [
'success' => false,
'message' => __('False')
];
}
(Magento\Framework\Controller\Result\JsonFactory)
$resultJson = $this->jsonFactory->create();
$resultJson->setData($response);
return $resultJson;
My Controller implements Magento\Framework\App\Action\HttpPostActionInterface.
How i can fix it?
1 Answer 1
In general, HTTP responses of 500 will write an error to the Magento log if it is a Magento issue, and will not write to the Magento log if it is not a Magento issue. So first check the log:
$ cd /path/to/magento/installation
$ tail var/log/system.log
This is an answer to the general case of "Why am I getting 500 response". Once you know the answer to that question, you can start to debug the specific issue being faced.
-
Thank you. I just wanted to make an update on the issue, because I found the reason for the 500 code. I found the reason for 500 code. Sometimes my conditions were not met and the post request was not transmitted, so a 500 error occurredDavid Young– David Young2022年08月02日 12:45:01 +00:00Commented Aug 2, 2022 at 12:45