<s> from flask import render_template , request <EOL> from standup . utils import json_requested , jsonify <EOL> def register_error_handlers ( app ) : <EOL> app . register_error_handler ( <NUM_LIT> , forbidden ) <EOL> app . register_error_handler ( <NUM_LIT> , page_not_found ) <EOL> app . register_error_handler ( <NUM_LIT> , something_broke ) <EOL> def api_error ( code , message ) : <EOL> error = dict ( request = request . path , message = message ) <EOL> return jsonify ( error ) , code <EOL> def error ( code , message , template ) : <EOL> if json_requested ( ) : <EOL> return api_error ( code , str ( message ) ) <EOL> else : <EOL> return render_template ( template , error = message ) , code <EOL> def forbidden ( message = None ) : <EOL> message = message or '<STR_LIT>' <EOL> return error ( <NUM_LIT> , message , '<STR_LIT>' ) <EOL> def page_not_found ( message = None ) : <EOL> message = message or '<STR_LIT>' <EOL> return error ( <NUM_LIT> , message , '<STR_LIT>' ) <EOL> def something_broke ( message = None ) : <EOL> message = message or '<STR_LIT>' <EOL> return error ( <NUM_LIT> , message , '<STR_LIT>' ) <EOL> class ApiError ( Exception ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ApiError , self ) . __init__ ( * args ) <EOL> self . code = kwargs . pop ( '<STR_LIT:code>' , <NUM_LIT> ) </s>
