Skip to content

Commit 83c766d

Browse files
committed
Return HTTP exceptions from individual detectors
1 parent 7133fce commit 83c766d

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

detectors/built_in/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def detect_content(request: ContentAnalysisHttpRequest):
2626
if detector_kind in request.detector_params:
2727
try:
2828
message_detections += detector_registry.handle_request(content, request.detector_params)
29+
except HTTPException as e:
30+
raise e
2931
except Exception as e:
3032
raise HTTPException(status_code=500) from e
3133
detections.append(message_detections)

detectors/built_in/file_type_detectors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import json
2+
from fastapi import HTTPException
3+
24
import jsonschema
35
import xml.etree.ElementTree as ET
46
import xmlschema
@@ -197,5 +199,5 @@ def handle_request(self, content: str, detector_params: dict) -> List[ContentAna
197199
if result is not None:
198200
detections += [result]
199201
else:
200-
raise ValueError(f"Unrecognized file type: {file_type}")
202+
raise HTTPException(status_code=400, detail=f"Unrecognized file type: {file_type}")
201203
return detections

tests/detectors/builtIn/test_filetype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def test_detect_content_unrecognized_filetype(self, client: TestClient):
210210
"detector_params": {"file_type": ["not_a_type"]}
211211
}
212212
resp = client.post("/api/v1/text/contents", json=payload)
213-
assert resp.status_code == 500
213+
assert resp.status_code == 400
214214
data = resp.json()
215215
assert "message" in data
216216
assert "Unrecognized file type" in data["message"]

0 commit comments

Comments
 (0)