fraiseql_error/integration.rs
1/// Errors that occur when communicating with external integration services
2/// such as search engines, caches, or message queues.
3#[derive(Debug, thiserror::Error)]
4pub enum IntegrationError {
5 /// A search provider (e.g. Elasticsearch, Typesense) returned an error.
6 #[error("Search provider error: {provider} - {message}")]
7 Search {
8 /// Name of the search provider.
9 provider: String,
10 /// Error message from the provider.
11 message: String,
12 },
13
14 /// An error occurred while reading from or writing to an external cache
15 /// (e.g. Redis).
16 #[error("Cache error: {message}")]
17 Cache {
18 /// Description of the cache failure.
19 message: String,
20 },
21
22 /// An error occurred while interacting with a message queue or broker
23 /// (e.g. `RabbitMQ`, `NATS`).
24 #[error("Queue error: {message}")]
25 Queue {
26 /// Description of the queue failure.
27 message: String,
28 },
29
30 /// A network connection to an external service could not be established.
31 #[error("Connection failed: {service}")]
32 ConnectionFailed {
33 /// Name or address of the service that could not be reached.
34 service: String,
35 },
36
37 /// An operation against an external service did not complete within the
38 /// allowed time budget.
39 #[error("Timeout: {operation}")]
40 Timeout {
41 /// Name of the operation that timed out.
42 operation: String,
43 },
44}
45
46impl IntegrationError {
47 /// Returns a short, stable error code string suitable for API responses and
48 /// structured logging.
49 pub const fn error_code(&self) -> &'static str {
50 match self {
51 Self::Search { .. } => "integration_search_error",
52 Self::Cache { .. } => "integration_cache_error",
53 Self::Queue { .. } => "integration_queue_error",
54 Self::ConnectionFailed { .. } => "integration_connection_failed",
55 Self::Timeout { .. } => "integration_timeout",
56 }
57 }
58}