Skip to main content

google_analytics_api_ga4/error/
mod.rs

1use std::fmt::{Debug, Display, Formatter};
2
3#[derive(Debug, Clone)]
4pub enum GoogleApiError {
5    /// ネットワークレベルの失敗(接続不可、タイムアウトなど)
6    Connection(String),
7    /// レスポンスボディのJSONパース失敗
8    JsonParse(String),
9    /// APIが非2xxステータスを返した場合(ステータスコードとレスポンスボディ)
10    Response(u16, String),
11}
12
13impl Display for GoogleApiError {
14    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
15        match self {
16            GoogleApiError::Connection(e) => write!(f, "connection error: {}", e),
17            GoogleApiError::JsonParse(e) => write!(f, "json parse error: {}", e),
18            GoogleApiError::Response(status, body) => {
19                write!(f, "api error (status {}): {}", status, body)
20            }
21        }
22    }
23}
24
25impl std::error::Error for GoogleApiError {}