0

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?

asked Aug 2, 2022 at 9:41
0

1 Answer 1

0

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.

answered Aug 2, 2022 at 12:10
1
  • 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 occurred Commented Aug 2, 2022 at 12:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.