From 81e96b4162de649c29a7993b9d08d660ff0bc7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 13 Apr 2020 00:47:05 +0200 Subject: [PATCH] redo api return --- src/resources.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/resources.py b/src/resources.py index 907bd09..4fb0e74 100644 --- a/src/resources.py +++ b/src/resources.py @@ -35,33 +35,31 @@ class SampleResource(Resource): :return: """ if 'file' not in request.files: - return {"status": "error", "message": "no file found"}, 469 + return {"err_msg": "no file found"}, 469 else: soundfile = request.files['file'] if 'description' not in request.form: - return {"status": "error", "message": "no description found"}, 470 + return {"err_msg": "no description found"}, 470 else: description = request.form.get("description") if soundfile.content_type != 'audio/wave': LOGGER.info( f"Input file was not WAV.") - return {'status': 'error', 'message': 'Input file not a wave file.'}, 415 + return {'err_msg': 'Input file not a wave file.'}, 415 try: desc = json.loads(description) except Exception as e: LOGGER.exception(e) - return {'status': 'error', - 'message': 'Input JSON could not be parsed'}, 400 + return {'err_msg': 'Input JSON could not be parsed'}, 400 validate_errors = SampleSchema().validate(desc) if validate_errors: LOGGER.error( "Input JSON did not conform to schema. It was: {}", desc) - return {'status': 'error', - 'message': 'Input JSON schema invalid'}, 417 + return {'err_msg': 'Input JSON schema invalid'}, 417 xeger = Xeger(limit=30) generated_tag = xeger.xeger(r'^[a-zA-Z]+[0-9a-zA-Z_]*$') @@ -87,11 +85,11 @@ class SampleResource(Resource): except Exception as e: LOGGER.exception(e) db.session.rollback() - return {"status": "exception", "message": str( + return {"err_msg": str( e), "hint": "DB or downstream service error"}, 569 db.session.commit() - return {"status": "ok", "message": generated_tag}, 200 + return {"tag": generated_tag}, 200 def get(self): """ @@ -99,7 +97,7 @@ class SampleResource(Resource): :return: """ samples = SampleMetadata.query.all() - return jsonify({"status": "ok", "message": list(samples)}), 200 + return list(samples), 200 class SampleParameterResource(Resource): @@ -114,4 +112,4 @@ class SampleParameterResource(Resource): :return: """ sample = SampleMetadata.query.filter_by(tag=tag).first_or_404() - return jsonify({"status": "ok", "message": sample}), 200 + return sample, 200