public function onBeforeHTTPError($code, $request)
    {

        $errorPage = ErrorPage::get()->filter(array(
                'ErrorCode' => $code,
                'SiteID' => Multisites::inst()->getCurrentSiteId()
            ))->first();
        if ($errorPage) {
            Requirements::clear();
            Requirements::clear_combined_files();
            $response = ModelAsController::controller_for($errorPage)->handleRequest($request);
            throw new HTTPResponse_Exception($response, $code);
        }
    }