| 454 | | try: |
|---|
| 455 | | # try to return a nice error page if we are in production mode and http errors |
|---|
| 456 | | # are enabled |
|---|
| 457 | | isProduction = cherrypy.config.get('server.environment') == 'production' |
|---|
| 458 | | httpErrors = cherrypy.config.get('server.httpErrors') |
|---|
| 459 | | |
|---|
| 460 | | if isProduction and httpErrors: |
|---|
| 461 | | if not extrabody: |
|---|
| 462 | | extrabody = '' |
|---|
| 463 | | status, _body = cherrypy.lib.httperrors.getErrorPage(500, extrabody) |
|---|
| 464 | | headers = [('Content-Length', str(len(_body))), ('Content-Type', 'text/html')] |
|---|
| 465 | | return (status, headers, _body) |
|---|
| 466 | | else: |
|---|
| 467 | | # raise a dummy exception to force a plain error message |
|---|
| 468 | | raise Exception() |
|---|
| 469 | | except: |
|---|
| 470 | | # if there was a problem generating the error page |
|---|
| 471 | | # then return a basic message |
|---|
| 472 | | body = "Unrecoverable error in the server." |
|---|
| 473 | | if extrabody is not None: |
|---|
| 474 | | body += "\n" + extrabody |
|---|
| 475 | | |
|---|
| 476 | | return ("500 Internal Server Error", |
|---|
| 477 | | [('Content-Type', 'text/plain'), |
|---|
| 478 | | ('Content-Length', str(len(body)))], |
|---|
| 479 | | [body]) |
|---|
| | 454 | # The whole point of this function is to be a last line-of-defense |
|---|
| | 455 | # in handling errors. That is, it must not raise any errors itself; |
|---|
| | 456 | # it cannot be allowed to fail. Therefore, don't add to it! |
|---|
| | 457 | # In particular, don't call any other CP functions. |
|---|
| | 458 | body = "Unrecoverable error in the server." |
|---|
| | 459 | if extrabody is not None: |
|---|
| | 460 | body += "\n" + extrabody |
|---|
| | 461 | |
|---|
| | 462 | return ("500 Internal Server Error", |
|---|
| | 463 | [('Content-Type', 'text/plain'), |
|---|
| | 464 | ('Content-Length', str(len(body)))], |
|---|
| | 465 | [body]) |
|---|