@app.errorhandler(Exception)
def handle_error(e):
 error_type = type(e).__name__
 message = str(e)
 trace = None
 description = None
 status_code = 500
 if isinstance(e, werkzeug.exceptions.HTTPException):
  status_code = e.code
  description = e.description
 if app.debug:
  trace = traceback.format_exc()
 if request_wants_json():
  details = {'message': message, 'type': error_type}
  if (description is not None):
   details['description'] = description
  if (trace is not None):
   details['trace'] = trace.split('\n')
  return (flask.jsonify({'error': details}), status_code)
 else:
  return (flask.render_template('error.html', title=error_type, message=message, description=description, trace=trace), status_code)

@ app . errorhandler ( Exception ) def handle_error ( e ) : error_type = type ( e ) . __name__ message = str ( e ) trace = None description = None status_code = 500 if isinstance ( e , werkzeug . exceptions . HTTPException ) : status_code = e . code description = e . description if app . debug : trace = traceback . format_exc ( ) if request_wants_json ( ) : details = { 'message' : message , 'type' : error_type } if ( description is not None ) : details [ 'description' ] = description if ( trace is not None ) : details [ 'trace' ] = trace . split ( '\n' ) return ( flask . jsonify ( { 'error' : details } ) , status_code ) else : return ( flask . render_template ( 'error.html' , title = error_type , message = message , description = description , trace = trace ) , status_code )
extracts the last windows error message into a python unicode string .