errormiddleware.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # GNU MediaGoblin -- federated, autonomous media hosting
  2. # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. MGOBLIN_ERROR_MESSAGE = """\
  17. <div style="text-align:center;font-family: monospace">
  18. <h1>YEOWCH... that's an error!</h1>
  19. <pre>
  20. .-------------------------.
  21. | __ _ |
  22. | -, \_,------,_// |
  23. | <\ ,-- --.\ |
  24. | / (x ) ( X ) |
  25. | ' '--, ,--'\ |
  26. | / \ -v-v-u-v / |
  27. | . '.__.--__'.\ |
  28. | / ',___/ / \__/' |
  29. | | | ,'\_'/, || |
  30. | \_| | | | | || |
  31. | W',_ ||| |||_'' |
  32. | | '------'| |
  33. | |__| |_|_ |
  34. | ,,,-' '-,,, |
  35. '-------------------------'
  36. </pre>
  37. <p>Something bad happened, and things broke.</p>
  38. <p>If this is not your website, you may want to alert the owner.</p>
  39. <br><br>
  40. <p>
  41. Powered... er broken... by
  42. <a href="http://www.mediagoblin.org">MediaGoblin</a>,
  43. a <a href="http://www.gnu.org">GNU Project</a>.
  44. </p>
  45. </div>"""
  46. def mgoblin_error_middleware(app, global_conf, **kw):
  47. """
  48. MediaGoblin wrapped error middleware.
  49. This is really just wrapping the error middleware from Paste.
  50. It should take all of Paste's default options, so see:
  51. http://pythonpaste.org/modules/exceptions.html
  52. """
  53. # No paste? Fail in a friendly way!
  54. try:
  55. from paste.exceptions.errormiddleware import make_error_middleware
  56. except ImportError:
  57. return app
  58. kw['error_message'] = MGOBLIN_ERROR_MESSAGE
  59. return make_error_middleware(app, global_conf, **kw)