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