Changeset 605
- Timestamp:
- 09/04/05 16:06:05
- Files:
-
- trunk/cherrypy/_cperror.py (modified) (1 diff)
- trunk/cherrypy/_cphttptools.py (modified) (2 diffs)
- trunk/cherrypy/_cputil.py (modified) (2 diffs)
- trunk/cherrypy/_cpwsgi.py (modified) (1 diff)
- trunk/cherrypy/config.py (modified) (1 diff)
- trunk/cherrypy/lib/httperrors.py (added)
- trunk/cherrypy/test/test.py (modified) (1 diff)
- trunk/cherrypy/test/test_core.py (modified) (1 diff)
- trunk/cherrypy/test/test_gzip_filter.py (modified) (1 diff)
- trunk/cherrypy/tutorial/tut10_http_errors.py (copied) (copied from branches/httperrors/cherrypy/tutorial/tut10_http_errors.py)
- trunk/cherrypy/tutorial/tutorial.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cperror.py
r549 r605 185 185 if body is not _missing: 186 186 cherrypy.response.body = body 187 188 self.message = body 189 190 def getArgs(self): 191 return (self.status, self.message) 187 192 188 193 trunk/cherrypy/_cphttptools.py
r583 r605 429 429 # Bypass them all. 430 430 defaultOn = (cherrypy.config.get('server.environment') == 'development') 431 if cherrypy.config.get('s howTracebacks', defaultOn):431 if cherrypy.config.get('server.showTracebacks', defaultOn): 432 432 body = dbltrace % (_cputil.formatExc(exc), _cputil.formatExc()) 433 433 else: … … 449 449 """ 450 450 451 body = "Unrecoverable error in the server." 452 if extrabody is not None: 453 body += "\n" + extrabody 454 return ("500 Internal Server Error", 451 try: 452 isProduction = cherrypy.config.get('server.environment') == 'production' 453 httpErrors = cherrypy.config.get('server.httpErrors') 454 455 if isProduction and httpErrors: 456 if not extrabody: 457 extrabody = '' 458 status, _body = httperrors.getErrorPage(500, extrabody) 459 headers = [('Content-Length', str(len(_body))), ('Content-Type', 'text/html')] 460 return (status, headers, _body) 461 else: 462 # raise a dummy exception to force a plain error message 463 raise Exception() 464 except: 465 body = "Unrecoverable error in the server." 466 if extrabody is not None: 467 body += "\n" + extrabody 468 469 return ("500 Internal Server Error", 455 470 [('Content-Type', 'text/plain'), 456 471 ('Content-Length', str(len(body)))], trunk/cherrypy/_cputil.py
r573 r605 151 151 f.close() 152 152 153 from cherrypy.lib import httperrors 154 155 def _cpOnHTTPError(): 156 """ Default _cpOnHTTPError method """ 157 status, customMessage = sys.exc_info()[1].getArgs() 158 159 page = httperrors.getErrorPage(status, customMessage = customMessage) 160 cherrypy.response.status, cherrypy.response.body = page 161 162 if cherrypy.response.headerMap.has_key('Content-Encoding'): 163 del cherrypy.response.headerMap['Content-Encoding'] 153 164 154 165 def formatExc(exc=None): … … 160 171 def _cpOnError(): 161 172 """ Default _cpOnError method """ 162 defaultOn = (cherrypy.config.get('server.environment') == 'development') 163 if cherrypy.config.get("showTracebacks", defaultOn): 173 developmentMode = cherrypy.config.get('server.environment') == 'development' 174 httpErrors = cherrypy.config.get('server.httpErrors') 175 showTracebacks = cherrypy.config.get('server.showTracebacks') 176 177 response = cherrypy.response 178 179 if not developmentMode and httpErrors: 180 if response.status == 404: 181 response.status, response.body = httperrors.getErrorPage(404) 182 else: 183 response.status, response.body = httperrors.getErrorPage(500) 184 elif developmentMode or showTracebacks: 164 185 cherrypy.response.body = [formatExc()] 186 cherrypy.response.headerMap['Content-Type'] = 'text/plain' 165 187 else: 166 cherrypy.response.body = "Unrecoverable error in the application." 167 cherrypy.response.headerMap['Content-Type'] = 'text/plain' 188 if cherrypy.config.get('showTraceBacks', False): 189 cherrypy 190 cherrypy.response.body = "Unrecoverable error in the server" 191 cherrypy.response.headerMap['Content-Type'] = 'text/plain' 192 168 193 if cherrypy.response.headerMap.has_key('Content-Encoding'): 169 194 del cherrypy.response.headerMap['Content-Encoding'] 170 171 195 172 196 _cpFilterList = [] trunk/cherrypy/_cpwsgi.py
r583 r605 111 111 cherrypy.log(tb) 112 112 defaultOn = (cherrypy.config.get('server.environment') == 'development') 113 if not cherrypy.config.get("s howTracebacks", defaultOn):113 if not cherrypy.config.get("server.showTracebacks", defaultOn): 114 114 tb = "" 115 115 s, h, b = _cphttptools.bareError(tb) trunk/cherrypy/config.py
r585 r605 49 49 50 50 'server.environment': 'development', 51 'server.httpErrors' : True, 51 52 'server.protocolVersion': 'HTTP/1.0', 52 53 'server.logToScreen': True, trunk/cherrypy/test/test.py
r581 r605 251 251 'server.logToScreen': False, 252 252 'server.environment': "production", 253 's howTracebacks': True,253 'server.showTracebacks': True, 254 254 } 255 255 elif isinstance(conf, basestring): trunk/cherrypy/test/test_core.py
r580 r605 248 248 cherrypy.config.update({ 249 249 'global': {'server.logToScreen': False, 250 'server.httpErrors' : False, 250 251 'server.environment': 'production', 251 's howTracebacks': True,252 'server.showTracebacks': True, 252 253 'server.protocolVersion': "HTTP/1.1", 253 254 }, trunk/cherrypy/test/test_gzip_filter.py
r555 r605 46 46 'server.logToScreen': False, 47 47 'server.environment': 'production', 48 'showTracebacks': True, 48 'server.httpErrors': False, 49 'server.showTracebacks': True, 49 50 'gzipFilter.on': True, 50 51 }) trunk/cherrypy/tutorial/tutorial.conf
r420 r605 3 3 server.threadPool = 10 4 4 server.environment = "production" 5 # server.showTracebacks = True 5 6 # server.logToScreen = False

