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:
Adam Shimali
2016-06-14 15:07:23 +01:00
parent 5a66884f0e
commit b33312b855
16 changed files with 240 additions and 267 deletions

View File

@@ -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