Produce status, headers, body for a critical error. Returns a triple without calling any other questionable functions, so it should be as error-free as possible. Call it from an HTTP server if you get errors outside of the request. If extrabody is None, a friendly but rather unhelp
(extrabody=None)
| 590 | |
| 591 | |
| 592 | def bare_error(extrabody=None): |
| 593 | """Produce status, headers, body for a critical error. |
| 594 | |
| 595 | Returns a triple without calling any other questionable functions, |
| 596 | so it should be as error-free as possible. Call it from an HTTP |
| 597 | server if you get errors outside of the request. |
| 598 | |
| 599 | If extrabody is None, a friendly but rather unhelpful error message |
| 600 | is set in the body. If extrabody is a string, it will be appended |
| 601 | as-is to the body. |
| 602 | """ |
| 603 | |
| 604 | # The whole point of this function is to be a last line-of-defense |
| 605 | # in handling errors. That is, it must not raise any errors itself; |
| 606 | # it cannot be allowed to fail. Therefore, don't add to it! |
| 607 | # In particular, don't call any other CP functions. |
| 608 | |
| 609 | body = b'Unrecoverable error in the server.' |
| 610 | if extrabody is not None: |
| 611 | if not isinstance(extrabody, bytes): |
| 612 | extrabody = extrabody.encode('utf-8') |
| 613 | body += b'\n' + extrabody |
| 614 | |
| 615 | return (b'500 Internal Server Error', |
| 616 | [(b'Content-Type', b'text/plain'), |
| 617 | (b'Content-Length', ntob(str(len(body)), 'ISO-8859-1'))], |
| 618 | [body]) |