mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
Merge pull request #1636 from alphagov/get-rid-of-error-logging
downgrade lots of routine logging from error/exception to info
This commit is contained in:
@@ -234,7 +234,6 @@ def init_app(app):
|
|||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def page_not_found(e):
|
def page_not_found(e):
|
||||||
msg = e.description or "Not found"
|
msg = e.description or "Not found"
|
||||||
app.logger.exception(msg)
|
|
||||||
return jsonify(result='error', message=msg), 404
|
return jsonify(result='error', message=msg), 404
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -53,19 +53,19 @@ def register_errors(blueprint):
|
|||||||
|
|
||||||
@blueprint.errorhandler(ValidationError)
|
@blueprint.errorhandler(ValidationError)
|
||||||
def marshmallow_validation_error(error):
|
def marshmallow_validation_error(error):
|
||||||
current_app.logger.error(error)
|
current_app.logger.info(error)
|
||||||
return jsonify(result='error', message=error.messages), 400
|
return jsonify(result='error', message=error.messages), 400
|
||||||
|
|
||||||
@blueprint.errorhandler(JsonSchemaValidationError)
|
@blueprint.errorhandler(JsonSchemaValidationError)
|
||||||
def jsonschema_validation_error(error):
|
def jsonschema_validation_error(error):
|
||||||
current_app.logger.exception(error)
|
current_app.logger.info(error)
|
||||||
return jsonify(json.loads(error.message)), 400
|
return jsonify(json.loads(error.message)), 400
|
||||||
|
|
||||||
@blueprint.errorhandler(InvalidRequest)
|
@blueprint.errorhandler(InvalidRequest)
|
||||||
def invalid_data(error):
|
def invalid_data(error):
|
||||||
response = jsonify(error.to_dict())
|
response = jsonify(error.to_dict())
|
||||||
response.status_code = error.status_code
|
response.status_code = error.status_code
|
||||||
current_app.logger.error(error)
|
current_app.logger.info(error)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@blueprint.errorhandler(400)
|
@blueprint.errorhandler(400)
|
||||||
@@ -92,12 +92,11 @@ def register_errors(blueprint):
|
|||||||
@blueprint.errorhandler(NoResultFound)
|
@blueprint.errorhandler(NoResultFound)
|
||||||
@blueprint.errorhandler(DataError)
|
@blueprint.errorhandler(DataError)
|
||||||
def no_result_found(e):
|
def no_result_found(e):
|
||||||
current_app.logger.exception(e)
|
current_app.logger.info(e)
|
||||||
return jsonify(result='error', message="No result found"), 404
|
return jsonify(result='error', message="No result found"), 404
|
||||||
|
|
||||||
@blueprint.errorhandler(SQLAlchemyError)
|
@blueprint.errorhandler(SQLAlchemyError)
|
||||||
def db_error(e):
|
def db_error(e):
|
||||||
current_app.logger.exception(e)
|
|
||||||
if hasattr(e, 'orig') and hasattr(e.orig, 'pgerror') and e.orig.pgerror and \
|
if hasattr(e, 'orig') and hasattr(e.orig, 'pgerror') and e.orig.pgerror and \
|
||||||
('duplicate key value violates unique constraint "services_name_key"' in e.orig.pgerror or
|
('duplicate key value violates unique constraint "services_name_key"' in e.orig.pgerror or
|
||||||
'duplicate key value violates unique constraint "services_email_from_key"' in e.orig.pgerror):
|
'duplicate key value violates unique constraint "services_email_from_key"' in e.orig.pgerror):
|
||||||
@@ -107,6 +106,7 @@ def register_errors(blueprint):
|
|||||||
e.params.get('name', e.params.get('email_from', ''))
|
e.params.get('name', e.params.get('email_from', ''))
|
||||||
)]}
|
)]}
|
||||||
), 400
|
), 400
|
||||||
|
current_app.logger.exception(e)
|
||||||
return jsonify(result='error', message="Internal server error"), 500
|
return jsonify(result='error', message="Internal server error"), 500
|
||||||
|
|
||||||
# this must be defined after all other error handlers since it catches the generic Exception object
|
# this must be defined after all other error handlers since it catches the generic Exception object
|
||||||
|
|||||||
@@ -62,19 +62,19 @@ def register_errors(blueprint):
|
|||||||
def invalid_format(error):
|
def invalid_format(error):
|
||||||
# Please not that InvalidEmailError is re-raised for InvalidEmail or InvalidPhone,
|
# Please not that InvalidEmailError is re-raised for InvalidEmail or InvalidPhone,
|
||||||
# work should be done in the utils app to tidy up these errors.
|
# work should be done in the utils app to tidy up these errors.
|
||||||
current_app.logger.exception(error)
|
current_app.logger.info(error)
|
||||||
return jsonify(status_code=400,
|
return jsonify(status_code=400,
|
||||||
errors=[{"error": error.__class__.__name__, "message": str(error)}]), 400
|
errors=[{"error": error.__class__.__name__, "message": str(error)}]), 400
|
||||||
|
|
||||||
@blueprint.errorhandler(InvalidRequest)
|
@blueprint.errorhandler(InvalidRequest)
|
||||||
def invalid_data(error):
|
def invalid_data(error):
|
||||||
current_app.logger.error(error)
|
current_app.logger.info(error)
|
||||||
response = jsonify(error.to_dict_v2()), error.status_code
|
response = jsonify(error.to_dict_v2()), error.status_code
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@blueprint.errorhandler(ValidationError)
|
@blueprint.errorhandler(ValidationError)
|
||||||
def validation_error(error):
|
def validation_error(error):
|
||||||
current_app.logger.exception(error)
|
current_app.logger.info(error)
|
||||||
return jsonify(json.loads(error.message)), 400
|
return jsonify(json.loads(error.message)), 400
|
||||||
|
|
||||||
@blueprint.errorhandler(JobIncompleteError)
|
@blueprint.errorhandler(JobIncompleteError)
|
||||||
@@ -84,7 +84,7 @@ def register_errors(blueprint):
|
|||||||
@blueprint.errorhandler(NoResultFound)
|
@blueprint.errorhandler(NoResultFound)
|
||||||
@blueprint.errorhandler(DataError)
|
@blueprint.errorhandler(DataError)
|
||||||
def no_result_found(e):
|
def no_result_found(e):
|
||||||
current_app.logger.exception(e)
|
current_app.logger.info(e)
|
||||||
return jsonify(status_code=404,
|
return jsonify(status_code=404,
|
||||||
errors=[{"error": e.__class__.__name__, "message": "No result found"}]), 404
|
errors=[{"error": e.__class__.__name__, "message": "No result found"}]), 404
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user