AutoRpa/rpa_oms/app/inbound/envelope.py

25 lines
753 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""批量信封。缺 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