def after_request(response): request_args = {} for each_arg in request.args: request_args[each_arg] = request.args[each_arg] if 'text/html' in response.headers['Content-Type']: return response diff = datetime.now() - g.start try: authorization_value = request.headers.get('Authorization') if authorization_value is None: authorization_value = '' token = authorization_value.replace('JWT ', '', 1) # userinfo = jwt.decode(token, current_app.config['SECRET_KEY']) # print(userinfo) request_log = { # 'id': current_user.id, 'request_path': request.path, 'request_args': request_args, 'request_method': request.method, 'response_time': diff, 'response_status': response.status_code, } except Exception as e: print(e) log.error('Logging error') return response if app.config['LOG_LEVEL'] == 'debug' and 'json' in response.headers['Content-Type']: request_log['response_data'] = json.loads(response.data.decode('utf-8')) try: log.info('request log', extra=request_log) except Exception as e: log.error('Logging error : %s', e) return response
def get_signage_image(filename): try: return send_file(os.path.join(current_app.config['SIGNAGE_IMAGE_FOLDER'], filename)) except HTTPException as e: log.error({"code": e.code, "description": e.description}) raise except IOError as e: log.critical('voice file problem : ' + e) return jsonify({'message': 'IO Error'}), 404 except exc.SQLAlchemyError as e: log.error({"code": e.code, "description": e.description}) db.session.rollback() return abort(403, message='Wrong Token') except Exception as e: log.critical('Unexpected Error : ' + e) return jsonify({'message': str(e)}), 500
def get_signage_image(filename): try: return send_file( os.path.join(current_app.config['SIGNAGE_IMAGE_FOLDER'], filename)) except HTTPException as e: log.error({"code": e.code, "description": e.description}) raise except IOError as e: log.critical('voice file problem : ' + e) return jsonify({'message': 'IO Error'}), 404 except exc.SQLAlchemyError as e: log.error({"code": e.code, "description": e.description}) db.session.rollback() return abort(403, message='Wrong Token') except Exception as e: log.critical('Unexpected Error : ' + e) return jsonify({'message': str(e)}), 500
def decorated_function(*args, **kwargs): # print session # temp token = request.headers.get('Authorization') if (token is None) or (len(token) < 7): abort(403, message='token invalid') token = token[6:] if token == '1': session['userid'] = 'admin' session['id'] = 1 session['token'] = '1' elif youngs_redis.get('token-' + token) is None: log.error('token invalid : token [' + token + ']') abort(403, message='token invalid') else: userinfo = ast.literal_eval(youngs_redis.get('token-' + token)) session['userid'] = userinfo['userid'] session['id'] = userinfo['id'] session['token'] = token log.info('token valid : user [' + session['userid'] + ']') return f(*args, **kwargs)
def decorated_function(*args, **kwargs): # print session # temp token = request.headers.get('Authorization') if (token is None) or (len(token) < 7): abort(403, message='token invalid') token = token[6:] if token == '1': session['userid'] = 'admin' session['id'] = 1 session['token'] = '1' elif youngs_redis.get('token-'+token) is None: log.error('token invalid : token [' + token + ']') abort(403, message='token invalid') else: userinfo = ast.literal_eval(youngs_redis.get('token-'+token)) session['userid'] = userinfo['userid'] session['id'] = userinfo['id'] session['token'] = token log.info('token valid : user [' + session['userid'] + ']') return f(*args, **kwargs)
def after_request(response): request_args = {} for each_arg in request.args: request_args[each_arg] = request.args[each_arg] if 'text/html' in response.headers['Content-Type']: return response diff = datetime.now() - g.start try: authorization_value = request.headers.get('Authorization') if authorization_value is None: authorization_value = '' token = authorization_value.replace('JWT ', '', 1) # userinfo = jwt.decode(token, current_app.config['SECRET_KEY']) # print(userinfo) request_log = { # 'id': current_user.id, 'request_path': request.path, 'request_args': request_args, 'request_method': request.method, 'response_time': diff, 'response_status': response.status_code, } except Exception as e: print(e) log.error('Logging error') return response if app.config['LOG_LEVEL'] == 'debug' and 'json' in response.headers[ 'Content-Type']: request_log['response_data'] = json.loads( response.data.decode('utf-8')) try: log.info('request log', extra=request_log) except Exception as e: log.error('Logging error : %s', e) return response
def handle_http_exception(e): log.error(e) raise
def handle_io_error(e): log.error("IOError : " + str(e)) raise
def handle_sqlalchemy_error(e): log.error(e) db.session.rollback() return jsonify({"message": "SQLAlchemy Error"}), 406
def handle_flush_error(e): log.error(e) return jsonify({"message": "Flush Error"}), 409
def handle_multiple_results_found(e): log.error(e) return jsonify({"message": "Multiple Results Found"}), 409
def handle_no_result_found(e): log.error(e) return jsonify({"message": "No Results Found"}), 404