From d72a9b7d44e36132a2b9cc7e10598c9b23623a3d Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Sat, 25 May 2024 16:49:52 -0400 Subject: [PATCH] splinter previous error handler --- .pre-commit-config.yaml | 4 ++ src/pyflask/apis/data.py | 7 +-- src/pyflask/apis/neuroconv.py | 52 ++++++------------- src/pyflask/apis/startup.py | 4 +- src/pyflask/app.py | 5 +- src/pyflask/errorHandlers/__init__.py | 1 - .../errorHandlers/notBadRequestException.py | 5 -- 7 files changed, 25 insertions(+), 53 deletions(-) delete mode 100644 src/pyflask/errorHandlers/__init__.py delete mode 100644 src/pyflask/errorHandlers/notBadRequestException.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 248023898..65e307872 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,19 +1,23 @@ repos: + - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace + - repo: https://github.com/psf/black rev: 24.4.2 hooks: - id: black exclude: ^docs/ + - repo: https://github.com/PyCQA/isort rev: 5.13.2 hooks: - id: isort + - repo: https://github.com/pre-commit/mirrors-prettier rev: "v4.0.0-alpha.8" hooks: diff --git a/src/pyflask/apis/data.py b/src/pyflask/apis/data.py index de6dfdc6d..7cdafdb57 100644 --- a/src/pyflask/apis/data.py +++ b/src/pyflask/apis/data.py @@ -2,7 +2,6 @@ import traceback -from errorHandlers import notBadRequestException from flask_restx import Namespace, Resource, reqparse from manageNeuroconv import generate_dataset, generate_test_data @@ -28,8 +27,7 @@ def post(self): arguments = generate_test_data_parser.parse_args() generate_test_data(output_path=arguments["output_path"]) except Exception as exception: - if notBadRequestException(exception): - data_api.abort(500, str(exception)) + data_api.abort(500, str(exception)) raise exception @@ -48,5 +46,4 @@ def post(self): return generate_dataset(input_path=arguments["input_path"], output_path=arguments["output_path"]) except Exception as exception: - if notBadRequestException(exception): - data_api.abort(500, str(exception)) + data_api.abort(500, str(exception)) diff --git a/src/pyflask/apis/neuroconv.py b/src/pyflask/apis/neuroconv.py index 015cb61e8..47a2af031 100644 --- a/src/pyflask/apis/neuroconv.py +++ b/src/pyflask/apis/neuroconv.py @@ -2,7 +2,6 @@ import traceback -from errorHandlers import notBadRequestException from flask import Response, request from flask_restx import Namespace, Resource, reqparse from manageNeuroconv import ( @@ -50,8 +49,7 @@ def get(self): **get_all_converter_info(), } except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) raise exception @@ -62,8 +60,7 @@ def post(self): try: return get_source_schema(neuroconv_api.payload) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/locate") @@ -73,8 +70,7 @@ def post(self): try: return locate_data(neuroconv_api.payload) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/locate/autocomplete") @@ -84,8 +80,7 @@ def post(self): try: return autocomplete_format_string(neuroconv_api.payload) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/metadata") @@ -97,8 +92,7 @@ def post(self): neuroconv_api.payload.get("source_data"), neuroconv_api.payload.get("interfaces") ) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/convert") @@ -109,8 +103,7 @@ def post(self): return convert_to_nwb(neuroconv_api.payload) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/alignment") @@ -121,8 +114,7 @@ def post(self): return get_interface_alignment(neuroconv_api.payload) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) validate_parser = neuroconv_api.parser() @@ -143,8 +135,7 @@ def post(self): return validate_metadata(args.get("parent"), args.get("function_name")) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/upload/project") @@ -163,8 +154,7 @@ def post(self): return upload_project_to_dandi(**upload_options) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/upload/folder") @@ -183,8 +173,7 @@ def post(self): return upload_folder_to_dandi(**upload_options) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/upload") @@ -206,8 +195,7 @@ def post(self): return upload_multiple_filesystem_objects_to_dandi(**neuroconv_api.payload) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/inspect_file") @@ -217,8 +205,7 @@ def post(self): try: return inspect_nwb_file(neuroconv_api.payload) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/inspect_folder") @@ -230,8 +217,7 @@ def post(self): return inspect_nwb_folder(url, neuroconv_api.payload) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/announce") @@ -243,8 +229,7 @@ def post(self): announcer.announce(data) return True except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/inspect") @@ -271,8 +256,7 @@ def post(self): return inspect_multiple_filesystem_objects(url, paths, **kwargs) except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/html") @@ -287,8 +271,7 @@ def post(self): return html except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) # Create an events endpoint @@ -301,5 +284,4 @@ def get(self): return Response(listen_to_neuroconv_events(), mimetype="text/event-stream") except Exception as exception: - if notBadRequestException(exception): - neuroconv_api.abort(500, str(exception)) + neuroconv_api.abort(500, str(exception)) diff --git a/src/pyflask/apis/startup.py b/src/pyflask/apis/startup.py index 63be4fd0a..823dbee00 100644 --- a/src/pyflask/apis/startup.py +++ b/src/pyflask/apis/startup.py @@ -1,6 +1,5 @@ """API endpoint definitions for startup operations.""" -from errorHandlers import notBadRequestException from flask_restx import Namespace, Resource startup_api = Namespace("startup", description="API for startup commands related to the NWB GUIDE.") @@ -40,6 +39,5 @@ def get(self): return True except Exception as exception: - if notBadRequestException(exception=exception): - startup_api.abort(500, str(exception)) + startup_api.abort(500, str(exception)) raise exception diff --git a/src/pyflask/app.py b/src/pyflask/app.py index 619ee9a0e..9929ce625 100644 --- a/src/pyflask/app.py +++ b/src/pyflask/app.py @@ -12,8 +12,6 @@ from signal import SIGINT from urllib.parse import unquote -from errorHandlers import notBadRequestException - # https://stackoverflow.com/questions/32672596/pyinstaller-loads-script-multiple-times#comment103216434_32677108 multiprocessing.freeze_support() @@ -128,8 +126,7 @@ def post(self): selected_logger(message) except Exception as exception: - if notBadRequestException(exception): - api.abort(500, str(exception)) + api.abort(500, str(exception)) @api.route("/server_shutdown", endpoint="shutdown") diff --git a/src/pyflask/errorHandlers/__init__.py b/src/pyflask/errorHandlers/__init__.py deleted file mode 100644 index b88aad104..000000000 --- a/src/pyflask/errorHandlers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .notBadRequestException import notBadRequestException diff --git a/src/pyflask/errorHandlers/notBadRequestException.py b/src/pyflask/errorHandlers/notBadRequestException.py deleted file mode 100644 index c0f002952..000000000 --- a/src/pyflask/errorHandlers/notBadRequestException.py +++ /dev/null @@ -1,5 +0,0 @@ -def notBadRequestException(exception): - """ - Check if the exception is a generic exception. - """ - return type(exception).__name__ not in ["BadRequest", "Forbidden", "Unauthorized"]