about summary refs log tree commit diff
path: root/uploader/population
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/population
parent1b6b9a90a4dbe38aefc00293309fb48d9f478b13 (diff)
downloadgn-uploader-0729e38e2f5bbc5ab23153adfed3d35ee59dc3d5.tar.gz
Extract common functionality into reusable function.
Diffstat (limited to 'uploader/population')
-rw-r--r--uploader/population/views.py28
1 files changed, 7 insertions, 21 deletions
diff --git a/uploader/population/views.py b/uploader/population/views.py
index 23bf242..3638453 100644
--- a/uploader/population/views.py
+++ b/uploader/population/views.py
@@ -2,9 +2,7 @@
 import re
 import json
 import base64
-import traceback
 
-from requests.models import Response
 from MySQLdb.cursors import DictCursor
 from flask import (flash,
                    request,
@@ -18,10 +16,11 @@ from uploader.oauth2.client import oauth2_post
 from uploader.ui import make_template_renderer
 from uploader.authorisation import require_login
 from uploader.genotypes.views import genotypesbp
-from uploader.phenotypes.views import phenotypesbp
-from uploader.expression_data.views import exprdatabp
 from uploader.db_utils import database_connection
 from uploader.datautils import enumerate_sequence
+from uploader.phenotypes.views import phenotypesbp
+from uploader.expression_data.views import exprdatabp
+from uploader.monadic_requests import make_either_error_handler
 from uploader.species.models import (all_species,
                                      species_by_id,
                                      order_species_by_family)
@@ -174,22 +173,6 @@ def create_population(species_id: int):
             "GeneticType": request.form.get("population_genetic_type") or None
         })
 
-        def __handle_error__(error):
-            error_format = (
-                "\n\nThere was an error creating the population:\n\t%s\n\n")
-            if issubclass(type(error), Exception):
-                app.logger.debug(error_format, traceback.format_exc())
-                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(error_format, error)
-            raise Exception(error)
-
         def __flash_success__(_success):
             flash("Successfully created resource.", "alert-success")
             return redirect(url_for(
@@ -206,7 +189,10 @@ def create_population(species_id: int):
                 "population_id": new_population["Id"],
                 "public": "on"
             }
-        ).either(__handle_error__, __flash_success__)
+        ).either(
+            make_either_error_handler(
+                "There was an error creating the population"),
+            __flash_success__)
 
 
 @popbp.route("/<int:species_id>/populations/<int:population_id>",