A generic error handler

def error(code, message, template):
    """A generic error handler"""
    if json_requested():
        return json_error(code, message)
    else:
        return render_template(template, message=message), code