From 919d4a43d3d386aa54c4b1186d4f3cd1efff15be Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 6 Jul 2021 16:23:31 +0200 Subject: [PATCH] return validating error --- ereuse_devicehub/resources/tradedocument/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/tradedocument/views.py b/ereuse_devicehub/resources/tradedocument/views.py index 4222eceb..a478da6f 100644 --- a/ereuse_devicehub/resources/tradedocument/views.py +++ b/ereuse_devicehub/resources/tradedocument/views.py @@ -2,6 +2,7 @@ import os import time from datetime import datetime from flask import current_app as app, request, g, Response +from marshmallow import ValidationError from teal.resource import View from ereuse_devicehub.db import db @@ -19,7 +20,11 @@ class TradeDocumentView(View): def post(self): """Add one document.""" - data = request.get_json(validate=True) + try: + data = request.get_json(validate=True) + except ValueError as err: + raise ValidationError(err) + hash3 = data['file_hash'] db_hash = ReportHash(hash3=hash3) db.session.add(db_hash)