-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-parse-error-responses.py
More file actions
42 lines (32 loc) · 1.55 KB
/
python-parse-error-responses.py
File metadata and controls
42 lines (32 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import annotations
import json
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[2]
def load_json(relative_path: str) -> dict:
return json.loads((REPO_ROOT / relative_path).read_text(encoding="utf-8"))
unauthorized_response = load_json("examples/api/unauthorized-response.sample.json")
forbidden_response = load_json("examples/api/forbidden-response.sample.json")
conflict_response = load_json("examples/api/conflict-response.sample.json")
error_response = load_json("examples/api/error-response.sample.json")
rate_limit_response = load_json("examples/api/rate-limit-response.sample.json")
stats_error_response = load_json("examples/api/stats-error-response.sample.json")
assert unauthorized_response["error"] == "Unauthorized"
assert forbidden_response["error"] == "Owner role required"
assert conflict_response["error"] == "Validation request conflicts with current state"
assert error_response["error"] == "Invalid validation payload"
assert rate_limit_response["error"] == "Rate limit exceeded"
assert stats_error_response["error"] == "Stats computation failed"
summary = {
"errorFamilies": [
unauthorized_response["error"],
forbidden_response["error"],
conflict_response["error"],
error_response["error"],
rate_limit_response["error"],
stats_error_response["error"],
],
"forbiddenMessage": forbidden_response["error"],
"rateLimitMessage": rate_limit_response["error"],
"statsFailureMessage": stats_error_response["error"],
}
print(json.dumps(summary, indent=2))