feat/agentic-commerce-x402-local-sim
py 44 lines 1.15 KB
Raw
1 """Safe, typed errors for the synthetic commerce flow."""
2
3 from __future__ import annotations
4
5 from collections.abc import Mapping
6
7
8 class CommerceError(RuntimeError):
9 """Base error with a stable, non-secret error code."""
10
11 def __init__(
12 self,
13 code: str,
14 message: str,
15 *,
16 diagnostics: Mapping[str, object] | None = None,
17 ) -> None:
18 super().__init__(message)
19 self.code = code
20 self.diagnostics = dict(diagnostics or {})
21
22
23 class ProtocolError(CommerceError):
24 """The merchant response did not satisfy the expected x402 shape."""
25
26
27 class PolicyDenied(CommerceError):
28 """Application-owned policy denied the proposed purchase."""
29
30
31 class IdempotencyConflict(CommerceError):
32 """An idempotency key was reused for a different purchase."""
33
34
35 class MerchantRejectedPayment(CommerceError):
36 """The synthetic merchant rejected the supplied payment proof."""
37
38
39 class LivePaymentDisabled(CommerceError):
40 """A networked live payment was attempted; Omnipay sim refuses it."""
41
42
43 class AgentResultInvalid(CommerceError):
44 """The agent result did not match application-observed purchase evidence."""