Project

General

Profile

Actions

Feature #69388

closed

Remove limitation: Ajax error status is hard coded

Added by Thomas Mayer over 8 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Could have
Assignee:
-
Category:
-
Target version:
-
Start date:
2015-08-28
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

As of TYPO3 CMS 7.5.0-dev, 85ce761, the http status for ajax errors is hard coded:

TYPO3\CMS\Core\Http\AjaxRequestHandler

protected function renderAsError() {
    /** @var Response $response */
    $response = GeneralUtility::makeInstance(Response::class);
    $response = $response
        ->withStatus(500, ' (AJAX)')
        ->withHeader('Content-type', 'text/xml; charset=utf-8')
        ->withHeader('X-JSON', 'false');
    $response->getBody()->write('<t3err>' . htmlspecialchars($this->errorMessage) . '</t3err>');
    return $response;
}

Suggestion would be to allow context specific http status codes. Status 500 stands for "Internal Server Error" which might be not suitable in many cases and blocks easy debugging.

Compare with the approach Twitter API has: https://dev.twitter.com/overview/api/response-codes.

A simple setter should do while status code 500 could still remain as a default. Which renders this issue non-breaking.

Actions #1

Updated by Thomas Mayer over 8 years ago

The new setter should be

public function setHttpStatus($httpStatus) {
    //set it
    return $this;
}

I'd also like to see an additional setter for internal error codes (which could be rendered as

<t3errno>1A23</t3errno>
):

public function setErrorCode($errorCode = '') {
    //set it
    return $this;
}

Plus, would it be nice to be able to cascade setters by returning $this, at least for the void methods (still non-breaking?):

public function setError($errorMsg = '', $httpStatus = 500) {
    $this->errorMessage = $errorMsg;
    $this->isError = TRUE;
    $this->setErrorCode($httpStatus); //default to 500 for errors
    return $this; //instead of void method
}

Plus, should the http status message not be hardcoded as '(AJAX)' but be resolved to a standard http status message (again, compare with Twitter API).

There's a nice collection of http codes and messages available at

TYPO3\CMS\Core\Http\AjaxRequestHandler\Response. Why not use it?

protected $availableStatusCodes = array(
    // INFORMATIONAL CODES
    100 => 'Continue',
    101 => 'Switching Protocols',
    102 => 'Processing',
    // SUCCESS CODES
    200 => 'OK',

Would be nice if the Response class could provide constants for status codes and a public function for message retrieval (optionally still keeping messages as constants as well).

There should also be a way to open the constants for http status codes and messages of the Response class to be widely used by extensions etc. This is currently not the case:

 * @internal Note that this is not public API yet.

TYPO3\CMS\Core\Utility\HttpUtility does not contain some codes which are in Response. Plus, are code and message not separated in HttpUtility (just complete strings).

TYPO3\CMS\Extbase\Mvc\Web\Response has at least most of the status codes but it does not provide a public getStatusMessage($statusCode) function. At least this class is not marked internal.

There should be a class which provides all http status codes and messages. And this class should be available for public use (including extensions). And it should be used by core components as well.

Actions #2

Updated by Thomas Mayer over 8 years ago

I could provide a patch for this as soon as there is some sort of clearance. Would like to see this done for the 7 LTS release.

Actions #3

Updated by Riccardo De Contardi over 7 years ago

AFAICS it is still present on the latest master 8.5.0-dev

Actions #5

Updated by Georg Ringer about 4 years ago

  • Status changed from New to Closed

closed because of no feedback and solved

Actions

Also available in: Atom PDF