From e696f9b1af0a2f445473bf9279f7d4444edabb02 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 11 Apr 2022 11:24:25 +0200 Subject: [PATCH] fix response with validation raise of the snapshot schemas --- ereuse_devicehub/api/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/api/views.py b/ereuse_devicehub/api/views.py index 98b71d42..7a894394 100644 --- a/ereuse_devicehub/api/views.py +++ b/ereuse_devicehub/api/views.py @@ -3,7 +3,7 @@ from binascii import Error as asciiError from flask import Blueprint from flask import current_app as app -from flask import g, request +from flask import g, jsonify, request from flask.views import View from marshmallow import ValidationError from werkzeug.exceptions import Unauthorized @@ -51,7 +51,12 @@ class InventoryView(LoginMix, SnapshotMix): self.tmp_snapshots = app.config['TMP_SNAPSHOTS'] self.path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email) snapshot_json = self.validate(snapshot_json) - self.snapshot_json = ParseSnapshotLsHw(snapshot_json).get_snapshot() + try: + self.snapshot_json = ParseSnapshotLsHw(snapshot_json).get_snapshot() + except ValidationError: + self.response = jsonify('') + self.response.status_code = 201 + return self.response snapshot = self.build() db.session.add(snapshot)