Skip to main content

fraiseql_error/
webhook.rs

1#[derive(Debug, thiserror::Error)]
2pub enum WebhookError {
3    #[error("Invalid signature")]
4    InvalidSignature,
5
6    #[error("Missing signature header: {header}")]
7    MissingSignature { header: String },
8
9    #[error("Timestamp too old: {age_seconds}s (max: {max_seconds}s)")]
10    TimestampExpired { age_seconds: u64, max_seconds: u64 },
11
12    #[error("Timestamp in future: {future_seconds}s")]
13    TimestampFuture { future_seconds: u64 },
14
15    #[error("Duplicate event: {event_id}")]
16    DuplicateEvent { event_id: String },
17
18    #[error("Unknown event type: {event_type}")]
19    UnknownEvent { event_type: String },
20
21    #[error("Provider not configured: {provider}")]
22    ProviderNotConfigured { provider: String },
23
24    #[error("Payload parse error: {message}")]
25    PayloadError { message: String },
26
27    #[error("Idempotency check failed: {message}")]
28    IdempotencyError { message: String },
29}
30
31impl WebhookError {
32    pub const fn error_code(&self) -> &'static str {
33        match self {
34            Self::InvalidSignature => "webhook_invalid_signature",
35            Self::MissingSignature { .. } => "webhook_missing_signature",
36            Self::TimestampExpired { .. } => "webhook_timestamp_expired",
37            Self::TimestampFuture { .. } => "webhook_timestamp_future",
38            Self::DuplicateEvent { .. } => "webhook_duplicate_event",
39            Self::UnknownEvent { .. } => "webhook_unknown_event",
40            Self::ProviderNotConfigured { .. } => "webhook_provider_not_configured",
41            Self::PayloadError { .. } => "webhook_payload_error",
42            Self::IdempotencyError { .. } => "webhook_idempotency_error",
43        }
44    }
45}