1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Custom HTTP errors?

Discussion in 'XenForo Development Discussions' started by Floren, Apr 15, 2014.

  1. Floren

    Floren Well-Known Member

    I would like to use custom HTTP errors in XenForo, I was wondering if someone could help post some simple guidelines how to do this?
    For example, I want to have something like:
    http://xenforo.com/community/401 - Returns a template message "Not Authorized"
    http://xenforo.com/community/404 - Returns a template message "Page Not Found"... etc.

    Thank you.
  2. Chris D

    Chris D XenForo Developer Staff Member

  3. Floren

    Floren Well-Known Member

    Hi Chris,

    What plan to do is edit the Resources code, instead of creating a separate add-on.
    I will extend the related function in Listener/Proxy/SomeAction.php and edit the Listener/Proxy.php to call it, like I did in this thread.

    I'm looking at XenForo code into getNotFoundResponse() but I cannot figure how I could trigger a setHttpResponseCode(401). I guess I have to extend the Controller.php and add a new function there, but how do I trigger it? I don't see anywhere called actionErrorNotFound().

    Thanks for your help.
    Last edited: Apr 16, 2014
  4. Floren

    Floren Well-Known Member

    Here is the code I plan to use in XenForo/Controller.php:
    public function getNotAuthorizedResponse()
        return $this->responseError(new XenForo_Phrase('requested_page_not_authorized'), 401);
    But what function do I use in XenForo/ControllerPublic/Error.php?
    Something like:
    class XenForo_ControllerPublic_Error extends XenForo_ControllerPublic_Abstract
        public function actionErrorNotAuthorized()
            return $this->getNotAuthorizedResponse();
    What I don't understand is how is the public function actionErrorNotFound() called, I don't see any reference anywhere? Thank you for your guidelines, guys.
  5. Jeremy P

    Jeremy P Well-Known Member

    Floren likes this.
  6. Floren

    Floren Well-Known Member

    Thanks, I'll look into it tomorrow... to tired now. :)

Share This Page