mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 16:28:01 -05:00
better error handling on missing templates in production environment. Also added a mobile 404 template
This commit is contained in:
@@ -296,7 +296,10 @@ class VUser(Validator):
|
||||
if not c.user_is_loggedin:
|
||||
#TODO return a real error page
|
||||
d = dict(dest=reddit_link(request.path, url = True) + utils.query_string(request.GET))
|
||||
return redirect_to("/login" + utils.query_string(d))
|
||||
path = "/login"
|
||||
if request.environ.get('extension'):
|
||||
path += ".%s" % request.environ['extension']
|
||||
return redirect_to(path + utils.query_string(d))
|
||||
if (password is not None) and not valid_password(c.user, password):
|
||||
c.errors.add(errors.WRONG_PASSWORD)
|
||||
|
||||
|
||||
@@ -19,19 +19,21 @@
|
||||
# All portions of the code written by CondeNet are Copyright (c) 2006-2008
|
||||
# CondeNet, Inc. All Rights Reserved.
|
||||
################################################################################
|
||||
from r2.lib.wrapped import Wrapped
|
||||
from r2.lib.wrapped import Wrapped, NoTemplateFound
|
||||
from r2.models import IDBuilder, LinkListing, Account, Default, FakeSubreddit, Subreddit
|
||||
from r2.config import cache
|
||||
from r2.lib.jsonresponse import json_respond
|
||||
from r2.lib.jsontemplates import is_api
|
||||
from pylons.i18n import _
|
||||
from pylons import c, request, g
|
||||
from pylons.controllers.util import abort, redirect_to
|
||||
|
||||
from r2.lib.captcha import get_iden
|
||||
from r2.lib.filters import spaceCompress, _force_unicode
|
||||
from r2.lib.menus import NavButton, NamedButton, NavMenu, PageNameNav, JsButton, menu
|
||||
from r2.lib.strings import plurals, rand_strings, strings
|
||||
from r2.lib.utils import title_to_url
|
||||
import sys
|
||||
|
||||
def get_captcha():
|
||||
if not c.user_is_loggedin or c.user.needs_captcha():
|
||||
@@ -135,12 +137,21 @@ class Reddit(Wrapped):
|
||||
In adition, unlike Wrapped.render, the result is in the form of a pylons
|
||||
Response object with it's content set.
|
||||
"""
|
||||
res = Wrapped.render(self, *a, **kw)
|
||||
if is_api():
|
||||
res = json_respond(res)
|
||||
elif self.space_compress:
|
||||
res = spaceCompress(res)
|
||||
c.response.content = res
|
||||
try:
|
||||
res = Wrapped.render(self, *a, **kw)
|
||||
if is_api():
|
||||
res = json_respond(res)
|
||||
elif self.space_compress:
|
||||
res = spaceCompress(res)
|
||||
c.response.content = res
|
||||
except NoTemplateFound, e:
|
||||
# re-raise the error -- development environment
|
||||
if g.debug:
|
||||
s = sys.exc_info()
|
||||
raise s[1], None, s[2]
|
||||
# die gracefully -- production environment
|
||||
else:
|
||||
abort(404, "not found")
|
||||
return c.response
|
||||
|
||||
def corner_buttons(self):
|
||||
|
||||
@@ -47,7 +47,7 @@ class Wrapped(object):
|
||||
pass
|
||||
|
||||
if not found:
|
||||
raise AttributeError, attr
|
||||
raise NoTemplateFound, attr
|
||||
|
||||
setattr(self, attr, res)
|
||||
return res
|
||||
@@ -71,8 +71,8 @@ class Wrapped(object):
|
||||
else:
|
||||
try:
|
||||
template = tpm.get(self, style, cache = not debug)
|
||||
except KeyError:
|
||||
raise NoTemplateFound, repr(self)
|
||||
except AttributeError:
|
||||
raise NoTemplateFound, (repr(self), style)
|
||||
|
||||
return template
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
## the Original Code is CondeNet, Inc.
|
||||
##
|
||||
## All portions of the code written by CondeNet are Copyright (c) 2006-2008
|
||||
## CondeNet, Inc. All Rights Reserved.
|
||||
## CondeNet, Inc. All Rights Reserved."
|
||||
################################################################################
|
||||
|
||||
<div style="text-align: center;">
|
||||
|
||||
26
r2/r2/templates/unfoundpage.mobile
Normal file
26
r2/r2/templates/unfoundpage.mobile
Normal file
@@ -0,0 +1,26 @@
|
||||
## "The contents of this file are subject to the Common Public Attribution
|
||||
## License Version 1.0. (the "License"); you may not use this file except in
|
||||
## compliance with the License. You may obtain a copy of the License at
|
||||
## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
|
||||
## License Version 1.1, but Sections 14 and 15 have been added to cover use of
|
||||
## software over a computer network and provide for limited attribution for the
|
||||
## Original Developer. In addition, Exhibit A has been modified to be consistent
|
||||
## with Exhibit B.
|
||||
##
|
||||
## Software distributed under the License is distributed on an "AS IS" basis,
|
||||
## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
||||
## the specific language governing rights and limitations under the License.
|
||||
##
|
||||
## The Original Code is Reddit.
|
||||
##
|
||||
## The Original Developer is the Initial Developer. The Initial Developer of
|
||||
## the Original Code is CondeNet, Inc.
|
||||
##
|
||||
## All portions of the code written by CondeNet are Copyright (c) 2006-2008
|
||||
## CondeNet, Inc. All Rights Reserved."
|
||||
################################################################################
|
||||
|
||||
<div style="text-align: center;">
|
||||
<img src="/static/reddit404${thing.choice}.png" alt="reddit is sad" />
|
||||
<p class="error">${_("the page you requested does not exist")}</p>
|
||||
</div>
|
||||
Reference in New Issue
Block a user