xmtp_api_grpc/
error.rs

1use thiserror::Error;
2use xmtp_proto::ConversionError;
3
4#[derive(Debug, Error)]
5pub enum GrpcBuilderError {
6    #[error("app version required to create client")]
7    MissingAppVersion,
8    #[error("libxmtp core library version required to create client")]
9    MissingLibxmtpVersion,
10    #[error("host url required to create client")]
11    MissingHostUrl,
12    #[error("xmtpd gateway url required to create client")]
13    MissingXmtpdGatewayUrl,
14    #[error(transparent)]
15    Metadata(#[from] tonic::metadata::errors::InvalidMetadataValue),
16    #[error("Invalid URI during channel creation")]
17    InvalidUri(#[from] http::uri::InvalidUri),
18    #[error(transparent)]
19    Url(#[from] url::ParseError),
20    #[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
21    #[error(transparent)]
22    Transport(#[from] tonic::transport::Error),
23}
24
25#[derive(Debug, Error)]
26pub enum GrpcError {
27    #[error("Invalid URI during channel creation")]
28    InvalidUri(#[from] http::uri::InvalidUri),
29    #[error(transparent)]
30    Metadata(#[from] tonic::metadata::errors::InvalidMetadataValue),
31    #[error(transparent)]
32    Status(#[from] tonic::Status),
33    #[error("{0} not found/empty")]
34    NotFound(String),
35    #[error("Payload not expected")]
36    UnexpectedPayload,
37    #[error("payload is missing")]
38    MissingPayload,
39    #[error(transparent)]
40    Proto(#[from] xmtp_proto::ProtoError),
41    #[error(transparent)]
42    Decode(#[from] prost::DecodeError),
43    #[error("unreachable (Infallible)")]
44    Unreachable,
45    #[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
46    #[error(transparent)]
47    Transport(#[from] tonic::transport::Error),
48}
49
50impl From<ConversionError> for GrpcError {
51    fn from(error: ConversionError) -> Self {
52        GrpcError::NotFound(error.to_string())
53    }
54}
55
56impl xmtp_common::retry::RetryableError for GrpcError {
57    fn is_retryable(&self) -> bool {
58        true
59    }
60}