25 lines
753 B
Python
25 lines
753 B
Python
"""批量信封。缺 data、空数组、超过 100 条:整包 422,一条都不落。
|
||
|
||
单条字段错误不走这里,由 sales_goods 逐条 REJECTED,HTTP 仍 200。
|
||
"""
|
||
|
||
MAX_BATCH = 100
|
||
|
||
|
||
class EnvelopeError(Exception):
|
||
def __init__(self, message: str):
|
||
self.message = message
|
||
|
||
|
||
def parse_envelope(payload: object) -> list:
|
||
if not isinstance(payload, dict) or "data" not in payload:
|
||
raise EnvelopeError("缺少批量数据节点 data")
|
||
data = payload["data"]
|
||
if not isinstance(data, list):
|
||
raise EnvelopeError("data 必须是数组")
|
||
if len(data) == 0:
|
||
raise EnvelopeError("data 不能为空")
|
||
if len(data) > MAX_BATCH:
|
||
raise EnvelopeError("一批最多 100 条")
|
||
return data
|