Skip to content

Commit 9930d0e

Browse files
✨ add webhook error response
1 parent 5befe48 commit 9930d0e

3 files changed

Lines changed: 57 additions & 7 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from datetime import datetime
2+
3+
from mindee.parsing.common.common_response import CommonResponse
4+
from mindee.parsing.common.string_dict import StringDict
5+
from mindee.v2.parsing import ErrorResponse
6+
7+
8+
class FailedInferenceResponse(CommonResponse):
9+
"""Webhook payload returned when an inference fails before producing a result."""
10+
11+
inference_id: str
12+
"""UUID of the failed inference."""
13+
model_id: str
14+
"""UUID of the model used."""
15+
file_name: str
16+
"""Name of the input file."""
17+
file_alias: str
18+
"""Alias sent for the file, if any."""
19+
error: ErrorResponse
20+
"""Problem details for the failure, if available."""
21+
created_at: datetime
22+
"""Date and time when the inference was started."""
23+
24+
def __init__(self, raw_prediction: StringDict) -> None:
25+
super().__init__(raw_prediction)
26+
self.inference_id = raw_prediction["inference_id"]
27+
self.model_id = raw_prediction["model_id"]
28+
self.file_name = raw_prediction["file_name"]
29+
self.file_alias = raw_prediction["file_alias"]
30+
self.error = ErrorResponse(raw_prediction["error"])
31+
self.created_at = datetime.fromisoformat(raw_prediction["created_at"])

‎tests/v1/input/test_url_validation.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from mindee.mindee_http.response_validation import validate_url_for_source
55

66

7-
@pytest.mark.v1
87
class TestValidateUrlScheme:
98
def test_rejects_http(self):
109
with pytest.raises(MindeeSourceError, match="HTTPS"):
@@ -18,7 +17,6 @@ def test_accepts_https(self):
1817
validate_url_for_source("https://example.com/file.pdf")
1918

2019

21-
@pytest.mark.v1
2220
class TestValidateUrlUserinfo:
2321
def test_rejects_username_and_password(self):
2422
with pytest.raises(MindeeSourceError, match="credentials"):
@@ -29,7 +27,6 @@ def test_rejects_username_only(self):
2927
validate_url_for_source("https://user@example.com/file.pdf")
3028

3129

32-
@pytest.mark.v1
3330
class TestValidateUrlLoopbackHostnames:
3431
def test_rejects_localhost(self):
3532
with pytest.raises(MindeeSourceError, match="Loopback"):
@@ -48,7 +45,6 @@ def test_rejects_ip6_loopback(self):
4845
validate_url_for_source("https://ip6-loopback/file.pdf")
4946

5047

51-
@pytest.mark.v1
5248
class TestValidateUrlLoopbackIPs:
5349
def test_rejects_ipv4_loopback(self):
5450
with pytest.raises(MindeeSourceError, match="disallowed"):
@@ -63,7 +59,6 @@ def test_rejects_ipv6_loopback(self):
6359
validate_url_for_source("https://[::1]/file.pdf")
6460

6561

66-
@pytest.mark.v1
6762
class TestValidateUrlPrivateIPs:
6863
def test_rejects_rfc1918_10_block(self):
6964
with pytest.raises(MindeeSourceError, match="disallowed"):
@@ -90,7 +85,6 @@ def test_rejects_multicast(self):
9085
validate_url_for_source("https://224.0.0.1/file.pdf")
9186

9287

93-
@pytest.mark.v1
9488
class TestValidateUrlCgnat:
9589
def test_rejects_cgnat_start(self):
9690
with pytest.raises(MindeeSourceError, match="disallowed"):
@@ -105,7 +99,6 @@ def test_accepts_just_outside_cgnat(self):
10599
validate_url_for_source("https://100.128.0.1/file.pdf")
106100

107101

108-
@pytest.mark.v1
109102
class TestValidateUrlIpv6UniqueLocal:
110103
def test_rejects_ipv6_ula_fc(self):
111104
with pytest.raises(MindeeSourceError, match="disallowed"):
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import json
2+
from datetime import datetime
3+
4+
import pytest
5+
6+
from mindee.v2.parsing.failed_inference_response import FailedInferenceResponse
7+
from tests.utils import V2_DATA_DIR
8+
9+
10+
@pytest.mark.v2
11+
def test_should_load_when_failed():
12+
"""Should load when the webhook didn't return a correct reply."""
13+
14+
json_path = V2_DATA_DIR / "errors" / "webhook_error_500_failed.json"
15+
with json_path.open("r", encoding="utf-8") as fh:
16+
json_sample = json.load(fh)
17+
response = FailedInferenceResponse(json_sample)
18+
19+
assert response is not None
20+
assert response.inference_id == "12345678-1234-1234-1234-123456789ABC"
21+
assert response.file_name == "default_sample.jpg"
22+
assert response.file_alias == "dummy-alias.jpg"
23+
assert isinstance(response.created_at, datetime)
24+
assert response.error is not None
25+
assert response.error.status == 500
26+
assert response.error.code == "500-012"

0 commit comments

Comments
 (0)