use monk_sdk::MonkError;
match client.ingest(event).await {
Ok(resp) => {
println!("accepted: {}", resp.idempotency_key);
}
Err(MonkError::Validation(msg)) => {
// Fix the event and retry — the input is malformed
eprintln!("validation error: {msg}");
}
Err(MonkError::Api { status, code, message, request_id, .. }) => {
eprintln!("API error {status} [{code}]: {message} (request: {request_id})");
}
Err(MonkError::CircuitOpen) => {
// The server has been failing repeatedly — back off
eprintln!("circuit breaker is open, will retry later");
}
Err(MonkError::BufferFull { capacity }) => {
// Buffer is at capacity — consider switching to BackpressureStrategy::Block
eprintln!("buffer full ({capacity} events), event dropped");
}
Err(e) if e.is_retryable() => {
// Network or timeout errors — the SDK already retried, but you may
// want to re-enqueue or log for later
eprintln!("transient error after retries: {e}");
}
Err(e) => {
eprintln!("unrecoverable error: {e}");
}
}