firebase_rs_sdk/remote_config/
error.rs1use std::fmt::{Display, Formatter};
2
3#[derive(Clone, Debug, PartialEq, Eq)]
4pub enum RemoteConfigErrorCode {
5 InvalidArgument,
6 Internal,
7}
8
9impl RemoteConfigErrorCode {
10 pub fn as_str(&self) -> &'static str {
11 match self {
12 RemoteConfigErrorCode::InvalidArgument => "remote-config/invalid-argument",
13 RemoteConfigErrorCode::Internal => "remote-config/internal",
14 }
15 }
16}
17
18#[derive(Clone, Debug)]
19pub struct RemoteConfigError {
20 pub code: RemoteConfigErrorCode,
21 message: String,
22}
23
24impl RemoteConfigError {
25 pub fn new(code: RemoteConfigErrorCode, message: impl Into<String>) -> Self {
26 Self {
27 code,
28 message: message.into(),
29 }
30 }
31
32 pub fn code_str(&self) -> &'static str {
33 self.code.as_str()
34 }
35}
36
37impl Display for RemoteConfigError {
38 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
39 write!(f, "{} ({})", self.message, self.code_str())
40 }
41}
42
43impl std::error::Error for RemoteConfigError {}
44
45pub type RemoteConfigResult<T> = Result<T, RemoteConfigError>;
46
47pub fn invalid_argument(message: impl Into<String>) -> RemoteConfigError {
48 RemoteConfigError::new(RemoteConfigErrorCode::InvalidArgument, message)
49}
50
51pub fn internal_error(message: impl Into<String>) -> RemoteConfigError {
52 RemoteConfigError::new(RemoteConfigErrorCode::Internal, message)
53}