Defect #1165

SHOP extract service does not return HTTP code on error

Added by Blatti Yves almost 4 years ago. Updated almost 4 years ago.

Status:ClosedStart date:10/26/2015
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:SHOP
Target version:4.3.2
Affected version:4.3.0

Description

When an error occurs, the error code is embedded in XML message, but HTTP status code is 200.

Codes have been chosen to be used in HTTP codes: 200, 400, 401, 403, 409, 500 (see: https://forge.easysdi.org/projects/easysdi/wiki/4_shop_rest#Exception).
And it was originally specified: https://forge.easysdi.org/projects/easysdi/wiki/Archive_of_shop_rest_specification_works

History

#1 Updated by Blatti Yves almost 4 years ago

Proposed solution in php 5.4:

    private function sendResponse($code = 200, $response = null) {
        if ($response == null) {
            $response = $this->response;
        }

        //if code is not 200, set the http code to the value of error code
        if ($code != 200) {
            http_response_code((int) $code);
        }

        echo $response->saveXML();
        JFactory::getApplication()->close($code);
    }

Do we keep php < 5.4 compatibility ?

#2 Updated by Blatti Yves almost 4 years ago

Previous php versions: header('HTTP/1.1 404 Not Found');
But we have to set the message, and will force the HTTP version

#3 Updated by Blatti Yves almost 4 years ago

  • Description updated (diff)
  • Status changed from New to Affected
  • Assignee set to Blatti Yves

Looking at Joomla framework, they use PHP's header function and force HTTP version to 1.1

private $responseMap = array(
      300 => 'HTTP/1.1 300 Multiple Choices',
      301 => 'HTTP/1.1 301 Moved Permanently',
      302 => 'HTTP/1.1 302 Found',
      etc...
);
header($this->responseMap[$status]);

I propose to do the same.

#4 Updated by Blatti Yves almost 4 years ago

  • Description updated (diff)

#5 Updated by Blatti Yves almost 4 years ago

  • Status changed from Affected to Resolved
  • % Done changed from 0 to 100

rev. 9141

#6 Updated by Blatti Yves almost 4 years ago

  • Status changed from Resolved to To merge
  • Assignee changed from Blatti Yves to Van Hoecke Hélène

#7 Updated by Van Hoecke Hélène almost 4 years ago

  • Target version set to 4.3.2

#8 Updated by Van Hoecke Hélène almost 4 years ago

  • Status changed from To merge to Closed

#9 Updated by Van Hoecke Hélène almost 4 years ago

  • Assignee deleted (Van Hoecke Hélène )

Also available in: Atom PDF