Support Localized/Custom HTTP error messages.

anonymous avataranonymous created an issue

Currently, http errors result in english messages based on the messages built into the python HTTP Server. It would be nice to return localized messages based on the browser's Accept-Language or the server configuration.

It would also be nice if the errors supported basic conditional expressions based on the server configuration. This would allow error pages to contain links back to the refering page, or administrator contact issue.

Comments (6)

  1. Anonymous

    I have come up with a very basic, that only supports conditional substitutions.

    Sample template

    <h2>404 Not Found</h2>
    <p>
      No file could be found at <a href="$request_path">$request_path</a>
    </p>
    #if referer
      <p>
       You may wish to contact the webmaster of <a href="$referer">$referer</a> and ask them to update their site.
    </p>
    #elif foobar
    <p>$foobar$</p>
    #else
    <p>___</p>
    #endif
    <p>
    

    If blocks can not be nested and #if/elif/else/endif, must come at the beginning of the line.

  2. Robert Brewer

    _cputil.getErrorPage can receive arbitrary keyword-args, which will be interpolated into the template (which is also overridable). However, HTTPError doesn't yet support ''sending'' such arguments.

  3. Anonymous

    this does not really solve the problem. also other content then text/html is requested for (see ticket 340). for now i do a cherrypy._cputil._HTTPErrorTemplate = '... which is somehow ugly. would be nice to include this in config to have different pages/mimetypes by path which would also resolve 340.

  4. Anonymous

    I assume that if someone wants to spend time on changing the language of an error sent by its CP application, he would also spend time changing the overall layout to integrate it to its application.

    Therefore externalising the default template doesn't look like the right approach to me. In fact one can totally do what one wants already by implementing specific _cp_on_error and _cp_on_http_error handlers. Those are flexible enough to change CP error handling behavior.

    Maybe the book should provide more examples about it though.

    I think we should close this issue as invalid.

  5. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.