Skip to content

Instantly share code, notes, and snippets.

@ixmatus
Created December 22, 2013 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ixmatus/8077529 to your computer and use it in GitHub Desktop.
Save ixmatus/8077529 to your computer and use it in GitHub Desktop.
class Error(Base):
@view_config(context=Exception,
renderer="curbweb:templates/errors/server_error.pt")
def server_error(self):
self.request.response.status_int = 400
tbexc = tb.format_exc()
log.error(tbexc)
return {'error': "There was an error! Sorry about that!",
'doc_title': "Server Error",
'jsapp': 'main'}
@view_config(context=HTTPError,
renderer="curbweb:templates/errors/public_httperror.pt")
def http_error(self):
# Need to check for API interaction
accept = str(self.request.accept)
return {'code': self.context.code,
'message': str(self.context.code) + ' ' + self.context.title,
'doc_title': self.context.title,
'jsapp': 'main',
'accepts': accept}
@view_config(context=Forbidden)
def denied(self):
# Let's figure out if they /are/ authenticated or not
user_id = authenticated_userid(self.request)
if user_id is None:
url = route_url('login', self.request)
self.request.session.flash(
'You must be logged in to access that resource')
else:
if self.request.user.role.name == "suser":
url = route_url('console', self.request)
else:
url = route_url('dash', self.request)
self.request.session.flash(
'You do not have the proper permissions to access that resource')
self.request.session['last_url'] = self.request.path_qs
self.request.session.persist()
return HTTPFound(location=url)
@view_config(context=NotFound,
renderer="curbweb:/templates/errors/notfound.pt")
def notfound(self):
self.request.response.status_int = 404
return {'doc_title': "404 Not Found",
'jsapp': 'main',
'message': "I'm sorry we couldn't find the page you were looking for!"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment