store-api-py 0.6.0__tar.gz → 0.6.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {store_api_py-0.6.0 → store_api_py-0.6.2}/PKG-INFO +1 -1
- {store_api_py-0.6.0 → store_api_py-0.6.2}/pyproject.toml +1 -1
- {store_api_py-0.6.0 → store_api_py-0.6.2}/src/store_api_py/errors.py +38 -3
- {store_api_py-0.6.0 → store_api_py-0.6.2}/src/store_api_py.egg-info/PKG-INFO +1 -1
- {store_api_py-0.6.0 → store_api_py-0.6.2}/tests/test_error_matrix.py +20 -1
- {store_api_py-0.6.0 → store_api_py-0.6.2}/README.md +0 -0
- {store_api_py-0.6.0 → store_api_py-0.6.2}/setup.cfg +0 -0
- {store_api_py-0.6.0 → store_api_py-0.6.2}/src/store_api_py/__init__.py +0 -0
- {store_api_py-0.6.0 → store_api_py-0.6.2}/src/store_api_py/app.py +0 -0
- {store_api_py-0.6.0 → store_api_py-0.6.2}/src/store_api_py/params.py +0 -0
- {store_api_py-0.6.0 → store_api_py-0.6.2}/src/store_api_py.egg-info/SOURCES.txt +0 -0
- {store_api_py-0.6.0 → store_api_py-0.6.2}/src/store_api_py.egg-info/dependency_links.txt +0 -0
- {store_api_py-0.6.0 → store_api_py-0.6.2}/src/store_api_py.egg-info/requires.txt +0 -0
- {store_api_py-0.6.0 → store_api_py-0.6.2}/src/store_api_py.egg-info/top_level.txt +0 -0
- {store_api_py-0.6.0 → store_api_py-0.6.2}/tests/test_smoke.py +0 -0
|
@@ -25,9 +25,44 @@ def error_payload(code: str, message: str | None) -> dict[str, Any]:
|
|
|
25
25
|
return {"error": {"code": code, "message": message}}
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
_KNOWN_STORE_PREFIXES = (
|
|
29
|
+
('ERR_PERMISSION:', 'ERR_PERMISSION'),
|
|
30
|
+
# machine code 统一为 no_context(与 rust map_store_err / node mapError 同口径)
|
|
31
|
+
('ERR_NO_CONTEXT:', 'no_context'),
|
|
32
|
+
('ERR_TEXT2QUERY:', 'ERR_TEXT2QUERY'),
|
|
33
|
+
('ERR_GQL_PARSE:', 'GQL_PARSE'),
|
|
34
|
+
('ERR_NOT_FOUND:', 'not_found'),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _prefix_store_code(text: Any) -> str | None:
|
|
39
|
+
"""解析单段文本的 `ERR_*` 稳定前缀(与 rust errors.rs::store_code 同口径)。"""
|
|
40
|
+
if not isinstance(text, str):
|
|
41
|
+
return None
|
|
42
|
+
for prefix, cls in _KNOWN_STORE_PREFIXES:
|
|
43
|
+
if text == prefix[:-1]: # 宿主只给去冒号的 machine 前缀(如 code='ERR_NOT_FOUND')
|
|
44
|
+
return cls
|
|
45
|
+
if not text.startswith(prefix):
|
|
46
|
+
continue
|
|
47
|
+
rest = text[len(prefix):]
|
|
48
|
+
seg, sep, _ = rest.partition(':')
|
|
49
|
+
return seg if sep and seg else cls
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def store_code(err: Any) -> str:
|
|
54
|
+
"""store 错误的分类码:`ERR_*` 稳定前缀(err.code / message)优先;
|
|
55
|
+
其余保持既有口径(err.code → 类名 → STORE_ERROR),禁吞成通用错误。"""
|
|
56
|
+
if isinstance(err, str):
|
|
57
|
+
return _prefix_store_code(err) or err or 'STORE_ERROR'
|
|
58
|
+
code = getattr(err, 'code', None)
|
|
59
|
+
return (
|
|
60
|
+
_prefix_store_code(code)
|
|
61
|
+
or _prefix_store_code(str(err))
|
|
62
|
+
or code
|
|
63
|
+
or type(err).__name__
|
|
64
|
+
or "STORE_ERROR"
|
|
65
|
+
)
|
|
31
66
|
|
|
32
67
|
|
|
33
68
|
def invalid_body(message: str) -> StoreApiError:
|
|
@@ -49,4 +49,23 @@ def test_matrix_other_to_500():
|
|
|
49
49
|
r = map_error(_err("连接超时", "CONN_TIMEOUT"), PermissionError)
|
|
50
50
|
assert r.status_code == 500
|
|
51
51
|
assert r.code == "CONN_TIMEOUT"
|
|
52
|
-
assert r.message == "连接超时"
|
|
52
|
+
assert r.message == "连接超时"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_cross_language_err_prefix_code_matches_rust():
|
|
56
|
+
"""跨端 code 口径:同一 `ERR_*` 输入与 rust store_code 同 code(未知错误保持原样)。"""
|
|
57
|
+
cases = [
|
|
58
|
+
("ERR_NOT_FOUND:目标记录不存在(写条件未命中任何行,_id 不存在或已被删除)", "not_found"),
|
|
59
|
+
("ERR_NOT_FOUND", "not_found"),
|
|
60
|
+
("ERR_NO_CONTEXT:缺少请求上下文", "no_context"),
|
|
61
|
+
("ERR_NO_CONTEXT", "no_context"),
|
|
62
|
+
("ERR_PERMISSION:RBAC:无权写入", "RBAC"),
|
|
63
|
+
("ERR_TEXT2QUERY:档位不支持", "ERR_TEXT2QUERY"),
|
|
64
|
+
("ERR_GQL_PARSE:意外的 token", "GQL_PARSE"),
|
|
65
|
+
]
|
|
66
|
+
for message, code in cases:
|
|
67
|
+
r = map_error(Exception(message), PermissionError)
|
|
68
|
+
assert r.code == code, f"{message} ⇒ {code}"
|
|
69
|
+
|
|
70
|
+
unknown = _err("连接超时", "CONN_TIMEOUT")
|
|
71
|
+
assert map_error(unknown, PermissionError).code == "CONN_TIMEOUT"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|