diff options
author | Frederick Muriuki Muriithi | 2024-07-01 14:59:32 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-07-01 14:59:32 -0500 |
commit | a68fe177ae41f2e58a64b3f8dcf3f825d004eeca (patch) | |
tree | 076b90e1ff1b3efa9ffd2b42588fef24c6ce88ea /qc_app/upload | |
parent | f0434c14b1359f8decf712926e502bd98822b38c (diff) | |
download | gn-uploader-a68fe177ae41f2e58a64b3f8dcf3f825d004eeca.tar.gz |
Respond with JSON. Handle error messages on UI.
Diffstat (limited to 'qc_app/upload')
-rw-r--r-- | qc_app/upload/rqtl2.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index 31d5a9d..e691636 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -13,11 +13,11 @@ import MySQLdb as mdb from redis import Redis from MySQLdb.cursors import DictCursor from werkzeug.utils import secure_filename -from werkzeug.exceptions import NotFound, BadRequest from flask import ( flash, escape, request, + jsonify, url_for, redirect, Response, @@ -254,13 +254,21 @@ def upload_rqtl2_bundle_chunked_get(# pylint: disable=["unused-argument"] filename = request.args.get("resumableFilename", type=str) or "" chunk = request.args.get("resumableChunkNumber", type=int) or 0 if not(fileid or filename or chunk): - raise BadRequest("At least one required query parameter is missing.") + return jsonify({ + "message": "At least one required query parameter is missing.", + "error": "BadRequest", + "statuscode": 400 + }), 400 if Path(chunks_directory(fileid), chunk_name(filename, chunk)).exists(): return "OK" - raise NotFound(description=f"Chunk {chunk} was not found.") + return jsonify({ + "message": f"Chunk {chunk} was not found.", + "error": "NotFound", + "statuscode": 404 + }), 404 def __merge_chunks__(targetfile: Path, chunkpaths: tuple[Path, ...]) -> Path: @@ -294,7 +302,13 @@ def upload_rqtl2_bundle_chunked_post(species_id: int, population_id: int): _targetfile = Path(app.config["UPLOAD_FOLDER"], _fileid) if _targetfile.exists(): - raise BadRequest("The file has already been uploaded.") + return jsonify({ + "message": ( + "A file with a similar unique identifier has previously been " + "uploaded and possibly is/has being/been processed."), + "error": "BadRequest", + "statuscode": 400 + }), 400 # save chunk data chunks_directory(_fileid).mkdir(exist_ok=True) |