web/application.py
brancholdstable
changeset 7348 dce4fa28ae49
parent 7083 b8e35cde46e9
child 7428 5338d895b891
equal deleted inserted replaced
7317:5760d5fb4a8b 7348:dce4fa28ae49
   388                 raise StatusResponse(500, ex.dumps())
   388                 raise StatusResponse(500, ex.dumps())
   389             except NotFound:
   389             except NotFound:
   390                 raise StatusResponse(404, self.notfound_content(req))
   390                 raise StatusResponse(404, self.notfound_content(req))
   391             except ValidationError, ex:
   391             except ValidationError, ex:
   392                 self.validation_error_handler(req, ex)
   392                 self.validation_error_handler(req, ex)
   393             except (Unauthorized, BadRQLQuery, RequestError), ex:
   393             except Unauthorized, ex:
       
   394                 self.error_handler(req, ex, tb=False, code=403)
       
   395             except (BadRQLQuery, RequestError), ex:
   394                 self.error_handler(req, ex, tb=False)
   396                 self.error_handler(req, ex, tb=False)
   395             except BaseException, ex:
   397             except BaseException, ex:
   396                 self.error_handler(req, ex, tb=True)
   398                 self.error_handler(req, ex, tb=True)
   397             except:
   399             except:
   398                 self.critical('Catch all triggered!!!')
   400                 self.critical('Catch all triggered!!!')
   420             # the browser to move to the form since it hides the global
   422             # the browser to move to the form since it hides the global
   421             # messages.
   423             # messages.
   422             raise Redirect(req.form['__errorurl'].rsplit('#', 1)[0])
   424             raise Redirect(req.form['__errorurl'].rsplit('#', 1)[0])
   423         self.error_handler(req, ex, tb=False)
   425         self.error_handler(req, ex, tb=False)
   424 
   426 
   425     def error_handler(self, req, ex, tb=False):
   427     def error_handler(self, req, ex, tb=False, code=500):
   426         excinfo = sys.exc_info()
   428         excinfo = sys.exc_info()
   427         self.exception(repr(ex))
   429         self.exception(repr(ex))
   428         req.set_header('Cache-Control', 'no-cache')
   430         req.set_header('Cache-Control', 'no-cache')
   429         req.remove_header('Etag')
   431         req.remove_header('Etag')
   430         req.reset_message()
   432         req.reset_message()
   439             errview = self.vreg['views'].select('error', req)
   441             errview = self.vreg['views'].select('error', req)
   440             template = self.main_template_id(req)
   442             template = self.main_template_id(req)
   441             content = self.vreg['views'].main_template(req, template, view=errview)
   443             content = self.vreg['views'].main_template(req, template, view=errview)
   442         except:
   444         except:
   443             content = self.vreg['views'].main_template(req, 'error-template')
   445             content = self.vreg['views'].main_template(req, 'error-template')
   444         raise StatusResponse(500, content)
   446         raise StatusResponse(code, content)
   445 
   447 
   446     def need_login_content(self, req):
   448     def need_login_content(self, req):
   447         return self.vreg['views'].main_template(req, 'login')
   449         return self.vreg['views'].main_template(req, 'login')
   448 
   450 
   449     def loggedout_content(self, req):
   451     def loggedout_content(self, req):