From 1f85191863c7a31da0173a22f0d9cdf618b70586 Mon Sep 17 00:00:00 2001
From: pcain-usgs <pcain@usgs.gov>
Date: Tue, 4 May 2021 09:30:22 -0600
Subject: [PATCH] Raise value error with HTTPException

---
 geomagio/api/ws/algorithms.py | 12 ++++--------
 geomagio/residual/Reading.py  |  8 ++++++--
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/geomagio/api/ws/algorithms.py b/geomagio/api/ws/algorithms.py
index f2eeee314..bcc42a359 100644
--- a/geomagio/api/ws/algorithms.py
+++ b/geomagio/api/ws/algorithms.py
@@ -33,11 +33,7 @@ def get_dbdt(
 
 @router.post("/algorithms/residual", response_model=Reading)
 def calculate_residual(reading: Reading, adjust_reference: bool = True):
-    missing_types = reading.get_missing_measurement_types()
-    if len(missing_types) != 0:
-        missing_types = ", ".join(t.value for t in missing_types)
-        raise HTTPException(
-            status_code=400,
-            detail=f"Missing {missing_types} measurements in input reading",
-        )
-    return calculate(reading=reading, adjust_reference=adjust_reference)
+    try:
+        return calculate(reading=reading, adjust_reference=adjust_reference)
+    except ValueError as e:
+        raise HTTPException(status_code=400, detail=str(e))
diff --git a/geomagio/residual/Reading.py b/geomagio/residual/Reading.py
index 519245b69..437da4992 100644
--- a/geomagio/residual/Reading.py
+++ b/geomagio/residual/Reading.py
@@ -8,10 +8,14 @@ from pydantic import BaseModel
 from .. import TimeseriesUtility
 from ..TimeseriesFactory import TimeseriesFactory
 from .Absolute import Absolute
-from .Calculation import DECLINATION_TYPES, INCLINATION_TYPES, MARK_TYPES
 from .Measurement import Measurement, average_measurement
 from .Diagnostics import Diagnostics
-from .MeasurementType import MeasurementType
+from .MeasurementType import (
+    MeasurementType,
+    DECLINATION_TYPES,
+    INCLINATION_TYPES,
+    MARK_TYPES,
+)
 
 
 class Reading(BaseModel):
-- 
GitLab