mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 10:03:38 -04:00
Change endpoint responses where there are marshalling, unmarshalling
or param errors to raise invalid data exception. That will cause those responses to be handled in by errors.py, which will log the errors. Set most of schemas to strict mode so that marshmallow will raise exception rather than checking for errors in return tuple from load. Added handler to errors.py for marshmallow validation errors.
This commit is contained in:
@@ -19,7 +19,10 @@ notifications_statistics = Blueprint(
|
||||
__name__, url_prefix='/service/<service_id>/notifications-statistics'
|
||||
)
|
||||
|
||||
from app.errors import register_errors
|
||||
from app.errors import (
|
||||
register_errors,
|
||||
InvalidRequest
|
||||
)
|
||||
|
||||
register_errors(notifications_statistics)
|
||||
|
||||
@@ -34,9 +37,9 @@ def get_all_notification_statistics_for_service(service_id):
|
||||
limit_days=int(request.args['limit_days'])
|
||||
)
|
||||
except ValueError as e:
|
||||
error = '{} is not an integer'.format(request.args['limit_days'])
|
||||
current_app.logger.error(error)
|
||||
return jsonify(result="error", message={'limit_days': [error]}), 400
|
||||
message = '{} is not an integer'.format(request.args['limit_days'])
|
||||
errors = {'limit_days': [message]}
|
||||
raise InvalidRequest(errors, status_code=400)
|
||||
else:
|
||||
statistics = dao_get_notification_statistics_for_service(service_id=service_id)
|
||||
|
||||
@@ -46,9 +49,7 @@ def get_all_notification_statistics_for_service(service_id):
|
||||
|
||||
@notifications_statistics.route('/seven_day_aggregate')
|
||||
def get_notification_statistics_for_service_seven_day_aggregate(service_id):
|
||||
data, errors = week_aggregate_notification_statistics_schema.load(request.args)
|
||||
if errors:
|
||||
return jsonify(result='error', message=errors), 400
|
||||
data = week_aggregate_notification_statistics_schema.load(request.args).data
|
||||
date_from = data['date_from'] if 'date_from' in data else date(date.today().year, 4, 1)
|
||||
week_count = data['week_count'] if 'week_count' in data else 52
|
||||
stats = dao_get_7_day_agg_notification_statistics_for_service(
|
||||
|
||||
Reference in New Issue
Block a user