<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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