Hi Guys for a project i try to extend the Magento REST API. I have some problems with my error handling. I don't know how to send the right Http Response Code. I tried it with something like this:

    $this->_errorMessage($e->getMessage(), Mage_Api2_Model_Server::HTTP_BAD_REQUEST, array(
         'item' => $data

I get the right message as a response but the status code is always 207.

3 Answers 3


You can configure the whole HTTP response with the response object from a controller:

    ->setHeader('HTTP/1.0', YOUR_STATUS_CODE, true)
    ->setHeader('Content-Type', 'text/html') // can be changed to json, xml...

I am using the following approach please suggest me If I am using the wrong approach?

Included following class in my custom namespace

use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\NoSuchEntityException;

Return 400(bad Request)

        throw new InputException(__('Not a valid data'));

Return 404 (Not Found)

        throw new NoSuchEntityException(__('Not a valid data'));
  • This will send a stack trace to user which is not what you want to do
    – user487772
    Jun 17, 2021 at 12:35

$this->_errorMessage() is used by operations performing multi-create or multi-update to provide status of individual create/update operations. In this case HTTP status code is always set to multi-status (207).

If error is critical, use $this->_critical($message, $code). If execution can be continued, use $this->_error($message, $code).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.