bug PR-5.3-dev Pending

User tests: Successful: Unsuccessful:

avatar ManuelHu
ManuelHu
30 Apr 2025

Pull Request for Issue #45398.

Summary of Changes

set the error code on the HTTP response

this is similar to the other error renderes (i.e. copied from https://github.com/joomla/joomla-cms/blob/5.3-dev/libraries/src/Error/Renderer/JsonRenderer.php)

Testing Instructions

  1. set a menu item that shows an article as the home menu item
    2, open https://<your-site>/?format=feed -- of course, this is not a useful feed link (I know that; thats the whole point.

  2. see a response such as

<?xml version="1.0" encoding="UTF-8"?>
<error>
	<code>404</code>
	<message>View nicht gefunden [Name, Typ, Präfix]: article, feed, site</message>
</error>
  1. open the browser DevTools to see the http status code reported from the server

Actual result BEFORE applying this Pull Request

the HTTP response status is 200

Expected result AFTER applying this Pull Request

the HTTP response status (not the one listed as <code>404</code>) is actually 404

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar ManuelHu ManuelHu - open - 30 Apr 2025
avatar ManuelHu ManuelHu - change - 30 Apr 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 30 Apr 2025
Category Libraries
avatar richard67 richard67 - change - 30 Apr 2025
Title
set http status header for XML/feed responses
[5.3] Set http status header for XML/feed responses
avatar richard67 richard67 - edited - 30 Apr 2025
avatar brianteeman
brianteeman - comment - 30 Apr 2025

Not sure but is it not enough to add this single line in the function

\Joomla\CMS\Factory::getApplication()->setHeader('status', $error->getCode());

avatar ManuelHu
ManuelHu - comment - 30 Apr 2025

well, yes, if we assume that

  • XML is only ever sent over HTTP (i.e. CLIApplication has no setHeader method)
    I am not sure if this is the case?
  • and that every exception sets a HTTP status (which is not the case). The default value is 0, and 0 is not a valid HTTP status

note: a similar check is not only implemented in JsonRenderer, but also in ErrorDocument

$status = $this->_error->getCode();
if ($status < 400 || $status > 599) {
$status = 500;
}
$errorReporting = CmsFactory::getApplication()->get('error_reporting');
if ($errorReporting === "development" || $errorReporting === "maximum") {
$status .= ' ' . str_replace("\n", ' ', $this->_error->getMessage());
}
CmsFactory::getApplication()->setHeader('status', $status);

also in the joomla-framework/application documentation:
https://github.com/joomla-framework/application/blob/e063a4a308729b930d853e29a9f7c303cac68629/README.md?plain=1#L54

However, this check is missing in other places. Also note, I am not an export in this (all of this just based on my code reviw of the last day), so I am not really sure what to decide here.

avatar laoneo
laoneo - comment - 5 May 2025

The instanceof check is fine, but I think ->setHeader('status', $error->getCode() < 400 ? 500 : $error->getCode()); would be enough. Or do you see an issue with it?

avatar ManuelHu
ManuelHu - comment - 5 May 2025

No, this should be equivalent in all typical cases. This very verbose code is just the same as already in the Json response, but I can certainly simplify the code.

avatar ManuelHu ManuelHu - change - 6 May 2025
Labels Added: bug PR-5.3-dev
avatar ceford ceford - test_item - 24 May 2025 - Tested successfully
avatar ceford
ceford - comment - 24 May 2025

I have tested this item ✅ successfully on fbc2426

I see the network response code change from 200 to 404 after applying the patch and the Firefox Browser Tools show a problem icon. So it works as described but I can't comment on the experts comments.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45419.

Add a Comment

Login with GitHub to post a comment