mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05: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:
@@ -5,6 +5,7 @@ from flask import (
|
||||
)
|
||||
|
||||
from app.errors import register_errors
|
||||
|
||||
from app.schemas import event_schema
|
||||
from app.dao.events_dao import dao_create_event
|
||||
|
||||
@@ -15,8 +16,6 @@ register_errors(events)
|
||||
@events.route('', methods=['POST'])
|
||||
def create_event():
|
||||
data = request.get_json()
|
||||
event, errors = event_schema.load(data)
|
||||
if errors:
|
||||
return jsonify(result="error", message=errors), 400
|
||||
event = event_schema.load(data).data
|
||||
dao_create_event(event)
|
||||
return jsonify(data=event_schema.dump(event).data), 201
|
||||
|
||||
Reference in New Issue
Block a user