mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
46 lines
1.5 KiB
Rust
46 lines
1.5 KiB
Rust
use api_models::errors::types::{ApiError, ApiErrorResponse};
|
|
use common_utils::errors::{CustomResult, ErrorSwitch};
|
|
|
|
pub type AnalyticsResult<T> = CustomResult<T, AnalyticsError>;
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, thiserror::Error)]
|
|
pub enum AnalyticsError {
|
|
#[allow(dead_code)]
|
|
#[error("Not implemented: {0}")]
|
|
NotImplemented(&'static str),
|
|
#[error("Unknown Analytics Error")]
|
|
UnknownError,
|
|
#[error("Access Forbidden Analytics Error")]
|
|
AccessForbiddenError,
|
|
#[error("Failed to fetch currency exchange rate")]
|
|
ForexFetchFailed,
|
|
}
|
|
|
|
impl ErrorSwitch<ApiErrorResponse> for AnalyticsError {
|
|
fn switch(&self) -> ApiErrorResponse {
|
|
match self {
|
|
Self::NotImplemented(feature) => ApiErrorResponse::NotImplemented(ApiError::new(
|
|
"IR",
|
|
0,
|
|
format!("{feature} is not implemented."),
|
|
None,
|
|
)),
|
|
Self::UnknownError => ApiErrorResponse::InternalServerError(ApiError::new(
|
|
"HE",
|
|
0,
|
|
"Something went wrong",
|
|
None,
|
|
)),
|
|
Self::AccessForbiddenError => {
|
|
ApiErrorResponse::Unauthorized(ApiError::new("IR", 0, "Access Forbidden", None))
|
|
}
|
|
Self::ForexFetchFailed => ApiErrorResponse::InternalServerError(ApiError::new(
|
|
"HE",
|
|
0,
|
|
"Failed to fetch currency exchange rate",
|
|
None,
|
|
)),
|
|
}
|
|
}
|
|
}
|