discourse_webhooks/
error.rs

1//! Error types for the discourse-webhooks crate
2//!
3//! This module defines all error types that can occur when processing
4//! Discourse webhook events.
5
6use serde_json;
7use thiserror::Error;
8
9/// Errors that can occur when processing webhook events
10///
11/// The generic parameter `H` represents the error type from the event handler.
12#[derive(Error, Debug)]
13pub enum WebhookError<H> {
14    /// Failed to parse the webhook payload as JSON
15    #[error("Failed to parse webhook payload: {0}")]
16    ParseError(#[from] serde_json::Error),
17
18    /// Error occurred in the event handler
19    #[error("Handler error: {0}")]
20    HandlerError(H),
21
22    /// Webhook signature verification failed
23    #[error("Invalid webhook signature")]
24    InvalidSignature,
25
26    /// Invalid Discourse instance specified
27    #[error("Invalid Discourse instance: {0}")]
28    InvalidInstance(String),
29
30    /// General processing error
31    #[error("Webhook processing error: {0}")]
32    ProcessingError(String),
33
34    /// Unknown or unsupported event type
35    #[error("Unknown event type: {0}")]
36    UnknownEventType(String),
37}
38
39/// Convenience Result type for webhook operations
40///
41/// Uses `Box<dyn std::error::Error + Send + Sync>` as the default handler error type.
42pub type Result<T, H = Box<dyn std::error::Error + Send + Sync>> =
43    std::result::Result<T, WebhookError<H>>;