Magento – How to set HTTP Response Code in Custom REST API

apimagento-1.9modulerestweb services

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
    ));
    return;

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

Best Answer

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

$this->getResponse()
    ->clearHeaders()
    ->setHeader('HTTP/1.0', YOUR_STATUS_CODE, true)
    ->setHeader('Content-Type', 'text/html') // can be changed to json, xml...
    ->setBody(YOUR_RETURN_CONTENT);