Skip to content

Commit

Permalink
splinter previous error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed May 25, 2024
1 parent 8a0eae3 commit d72a9b7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 53 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
7 changes: 2 additions & 5 deletions src/pyflask/apis/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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


Expand All @@ -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))
52 changes: 17 additions & 35 deletions src/pyflask/apis/neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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


Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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))
4 changes: 1 addition & 3 deletions src/pyflask/apis/startup.py
Original file line number Diff line number Diff line change
@@ -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.")
Expand Down Expand Up @@ -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
5 changes: 1 addition & 4 deletions src/pyflask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion src/pyflask/errorHandlers/__init__.py

This file was deleted.

5 changes: 0 additions & 5 deletions src/pyflask/errorHandlers/notBadRequestException.py

This file was deleted.

0 comments on commit d72a9b7

Please sign in to comment.