Log exceptions

This commit is contained in:
Jack O'Sullivan 2019-08-23 14:38:13 +01:00
parent ec164efe30
commit 895e9aa9c4

View File

@ -1,13 +1,18 @@
import logging
from flask import Flask, jsonify from flask import Flask, jsonify
app = Flask(__name__) app = Flask(__name__)
from . import network from . import network
logger = logging.getLogger('gunicorn.error')
@app.errorhandler(404) @app.errorhandler(404)
def err_not_found(e): def err_not_found(e):
return jsonify({'Err': 'API not found'}), 404 return jsonify({'Err': 'API not found'}), 404
@app.errorhandler(Exception) @app.errorhandler(Exception)
def err(e): def err(e):
logger.exception(e)
return jsonify({'Err': f'Error: {e}'}), 500 return jsonify({'Err': f'Error: {e}'}), 500