openfga_client/
error.rs

1use std::sync::Arc;
2
3use tonic::codegen::StdError;
4
5use crate::generated::ReadRequestTupleKey;
6
7pub type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Debug, thiserror::Error, Clone)]
10pub enum Error {
11    #[error("Multiple stores with the name `{0}` found")]
12    AmbiguousStoreName(String),
13    #[error("Request to OpenFGA failed")]
14    RequestFailed(tonic::Status),
15    #[error("Too many pages")]
16    TooManyPages {
17        max_pages: u32,
18        tuple: ReadRequestTupleKey,
19    },
20    #[error("Invalid Endpoint: `{0}`")]
21    InvalidEndpoint(String),
22    #[error("Invalid Token: {reason}")]
23    InvalidToken { reason: String },
24    #[cfg(feature = "auth-middle")]
25    #[error("Failed to fetch or refresh Client Credentials: {0}")]
26    CredentialRefreshError(#[source] middle::Error),
27    #[error(
28        "Invalid OpenFGA Model Version: `{0}`. Model Versions must have the format `major.minor`"
29    )]
30    InvalidModelVersion(String),
31    #[error("Migration Hook for model version {version} failed: {error}")]
32    MigrationHookFailed {
33        version: String,
34        error: Arc<StdError>,
35    },
36    #[error("Store with Name `{0}` not found")]
37    StoreNotFound(String),
38    #[error("Multiple authorization models with model prefix `{model_prefix}` for version `{version}` found.")]
39    AmbiguousModelVersion {
40        model_prefix: String,
41        version: String,
42    },
43}
44
45impl Error {
46    // pub fn internal(
47    //     reason: impl Into<String>,
48    //     error: impl Into<Box<dyn std::error::Error + Send + Sync>>,
49    // ) -> Self {
50    //     Self::InternalError {
51    //         reason: reason.into(),
52    //         source: error.into(),
53    //     }
54    // }
55}