From 7a1a4d6b2ed214ccae346b4e204c34b71be1cfb6 Mon Sep 17 00:00:00 2001
From: David Hoese <david.hoese@ssec.wisc.edu>
Date: Mon, 6 Mar 2023 15:13:13 -0600
Subject: [PATCH] Move data API order check early on in the request handling

---
 metobsapi/data_api.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/metobsapi/data_api.py b/metobsapi/data_api.py
index 2e817f8..7f91c61 100644
--- a/metobsapi/data_api.py
+++ b/metobsapi/data_api.py
@@ -208,11 +208,6 @@ def handle_csv(frame, epoch, response_info, formatting_kwargs):
 def handle_json(frame, epoch, response_info, formatting_kwargs):
     package = {}
     order = formatting_kwargs.get("order", "columns")
-    if order not in ("column", "row"):
-        # bad order
-        frame = None
-        response_info["code"], response_info["message"] = data_responses.ERROR_MESSAGES["bad_order"]
-        response_info["status"] = "error"
     code = response_info.get("code", 200)
 
     if frame is not None and not frame.empty:
@@ -340,6 +335,9 @@ def get_format_handler(fmt: str, formatting_kwargs: dict) -> Callable | tuple:
     if fmt not in RESPONSE_HANDLERS:
         raise BadHandlerFormat(bad_format=fmt)
     handler_func = RESPONSE_HANDLERS[fmt]
+    if formatting_kwargs.get("order") not in ("column", "row"):
+        # bad order
+        raise create_formatted_error(partial(handler_func, formatting_kwargs={}), "bad_order")
     return partial(handler_func, formatting_kwargs=formatting_kwargs)
 
 
-- 
GitLab