Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore: add error module for x402 operations

Steven Enamakela861ab5ae8ce
diff --git a/crates/openhuman-core/src/web3/x402/ops/errors.rs b/crates/openhuman-core/src/web3/x402/ops/errors.rs
new file mode 100644
index 0000000000..9a710be237
--- /dev/null
+++ b/crates/openhuman-core/src/web3/x402/ops/errors.rs
@@ -0,0 +1,51 @@
+//! The x402 client's error type.
+
+#[derive(Debug)]
+pub enum X402Error {
+ Transport(reqwest::Error),
+ NoPaymentHeader,
+ NoPaymentOption,
+ AmountExceedsCap {
+ requested: u64,
+ cap: u64,
+ },
+ BudgetExceeded {
+ period: &'static str,
+ current: u64,
+ cap: u64,
+ },
+ Protocol(String),
+ Wallet(String),
+}
+
+impl std::fmt::Display for X402Error {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Self::Transport(e) => write!(f, "x402 transport: {e}"),
+ Self::NoPaymentHeader => write!(f, "402 response missing PAYMENT-REQUIRED header"),
+ Self::NoPaymentOption => {
+ write!(
+ f,
+ "no supported payment option (Solana exact or EVM exact) in 402 challenge"
+ )
+ }
+ Self::AmountExceedsCap { requested, cap } => {
+ write!(f, "x402 amount {requested} exceeds per-request cap {cap}")
+ }
+ Self::BudgetExceeded {
+ period,
+ current,
+ cap,
+ } => {
+ write!(
+ f,
+ "x402 {period} budget exceeded: {current}/{cap} atomic units"
+ )
+ }
+ Self::Protocol(msg) => write!(f, "x402 protocol: {msg}"),
+ Self::Wallet(msg) => write!(f, "x402 wallet: {msg}"),
+ }
+ }
+}
+
+impl std::error::Error for X402Error {}