about summary refs log tree commit diff
path: root/uploader/genotypes
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-27 11:40:08 -0500
committerFrederick Muriuki Muriithi2024-09-27 11:40:08 -0500
commit0729e38e2f5bbc5ab23153adfed3d35ee59dc3d5 (patch)
treebd33450676c54be6444261b00c1d683a17b5366a /uploader/genotypes
parent1b6b9a90a4dbe38aefc00293309fb48d9f478b13 (diff)
downloadgn-uploader-0729e38e2f5bbc5ab23153adfed3d35ee59dc3d5.tar.gz
Extract common functionality into reusable function.
Diffstat (limited to 'uploader/genotypes')
-rw-r--r--uploader/genotypes/views.py22
1 files changed, 5 insertions, 17 deletions
diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py
index 9f08ca6..0821eca 100644
--- a/uploader/genotypes/views.py
+++ b/uploader/genotypes/views.py
@@ -1,5 +1,4 @@
 """Views for the genotypes."""
-from requests.models import Response
 from MySQLdb.cursors import DictCursor
 from flask import (flash,
                    request,
@@ -14,6 +13,7 @@ from uploader.oauth2.client import oauth2_post
 from uploader.authorisation import require_login
 from uploader.db_utils import database_connection
 from uploader.species.models import all_species, species_by_id
+from uploader.monadic_requests import make_either_error_handler
 from uploader.request_checks import with_species, with_population
 from uploader.datautils import safe_int, order_by_family, enumerate_sequence
 from uploader.population.models import (populations_by_species,
@@ -186,21 +186,6 @@ def create_dataset(species: dict, population: dict, **kwargs):# pylint: disable=
                 species_id=species["SpeciesId"],
                 population_id=population["Id"]))
 
-        def __fail__(error):
-            msg = "There was an error creating the genotype dataset."
-            if issubclass(type(error), Exception):
-                app.logger.debug("\n\n%s (Exception)\n\n", msg, exc_info=True)
-                raise error
-            if issubclass(type(error), Response):
-                try:
-                    _data = error.json()
-                except Exception as _exc:
-                    raise Exception(error.content) from _exc
-                raise Exception(_data)
-
-            app.logger.debug("\n\n%s\n\n", msg)
-            raise Exception(error)
-
         return oauth2_post(
             "auth/resource/genotypes/create",
             json={
@@ -213,4 +198,7 @@ def create_dataset(species: dict, population: dict, **kwargs):# pylint: disable=
                 "dataset_shortname": form["geno-dataset-shortname"],
                 "public": "on"
             }
-        ).either(__fail__, __success__)
+        ).either(
+            make_either_error_handler(
+                "There was an error creating the genotype dataset."),
+            __success__)