I'm looking for a way to catch mako runtime errors using Bottle.
Runtime errors in python are catched using the following code:
# main.py
from lib import errors
import bottle
app = bottle.app()
app.error_handler = errors.handler
...
# lib/errors.py
from bottle import mako_template as template
def custom500(error):
return template('error/500')
handler = {
500: custom500
}
This works flawlessly, as exceptions are turned into 500 Internal Server Error.
I'd like to catch the mako runtime errors in a similar fashion, does anyone have a clue of how to achieve this?
You want to catch
mako.exceptions.SyntaxException
.This code works for me:
EDIT: Per your comment, here are some pointers on how to install this globally. Install a bottle plugin that wraps your functions in the mako.exceptions.SyntaxException try block.
Something along these lines: