This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new 59b7272  Distinguish user errors from internal failures
59b7272 is described below

commit 59b72726725159cf71bdc3176a12193aa0fbf9fd
Author: Sebb <[email protected]>
AuthorDate: Thu Nov 18 22:22:36 2021 +0000

    Distinguish user errors from internal failures
---
 server/endpoints/mbox.py  | 12 ++++--------
 server/endpoints/stats.py |  6 ++++--
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/server/endpoints/mbox.py b/server/endpoints/mbox.py
index c168384..fb6ee2b 100644
--- a/server/endpoints/mbox.py
+++ b/server/endpoints/mbox.py
@@ -82,14 +82,10 @@ async def process(
 
     try:
         query_defuzzed = plugins.defuzzer.defuzz(indata, list_override="@" in 
lid and lid or None)
-    except (ValueError, AssertionError) as e:  # If defuzzer encounters syntax 
errors, it will throw an AssertionError or ValueError
-        return aiohttp.web.Response(
-            headers={
-                "content-type": "text/plain",
-            },
-            status=500,
-            text=str(e),
-        )
+    except ValueError as ve:  # If defuzzer encounters syntax errors, it will 
throw a ValueError
+        return aiohttp.web.Response(headers={"content-type": "text/plain",}, 
status=400, text=str(ve))
+    except AssertionError as ae:  # If defuzzer encounters internal errors, it 
will throw an AssertionError
+        return aiohttp.web.Response(headers={"content-type": "text/plain",}, 
status=500, text=str(ae))
     results = await plugins.messages.query(
         session,
         query_defuzzed,
diff --git a/server/endpoints/stats.py b/server/endpoints/stats.py
index 9aedbc1..09d3ce8 100644
--- a/server/endpoints/stats.py
+++ b/server/endpoints/stats.py
@@ -44,8 +44,10 @@ async def process(
     try:
         query_defuzzed = plugins.defuzzer.defuzz(indata)
         query_defuzzed_nodate = plugins.defuzzer.defuzz(indata, nodate=True)
-    except (ValueError, AssertionError) as e:  # If defuzzer encounters syntax 
errors, it will throw an AssertionError or ValueError
-        return aiohttp.web.Response(headers={"content-type": "text/plain",}, 
status=500, text=str(e))
+    except ValueError as ve:  # If defuzzer encounters syntax errors, it will 
throw a ValueError
+        return aiohttp.web.Response(headers={"content-type": "text/plain",}, 
status=400, text=str(ve))
+    except AssertionError as ae:  # If defuzzer encounters internal errors, it 
will throw an AssertionError
+        return aiohttp.web.Response(headers={"content-type": "text/plain",}, 
status=500, text=str(ae))
     results = await plugins.messages.query(
         session, query_defuzzed, query_limit=server.config.database.max_hits
     )

Reply via email to