use serde::Deserialize;
use thiserror::Error;
use crate::api::shared::responses::error_response::JQuantsErrorResponse;
#[derive(Debug, Deserialize)]
pub struct ErrorResponse {
pub status_code: u16,
pub error_message: String,
}
impl std::fmt::Display for ErrorResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Status code: {}, Error message: {}",
self.status_code, self.error_message
)
}
}
impl std::error::Error for ErrorResponse {}
#[derive(Error, Debug)]
pub enum JQuantsError {
#[error("Invalid credentials provided. Status code: {status_code}, Body: {body}")]
InvalidCredentials {
status_code: u16,
body: JQuantsErrorResponse,
},
#[error("ID token is invalid or expired. Status code: {status_code}, Message: {body}")]
IdTokenInvalidOrExpired {
status_code: u16,
body: JQuantsErrorResponse,
},
#[error("API error occurred. Status code: {status_code}, Message: {body}")]
ApiError {
status_code: u16,
body: JQuantsErrorResponse,
},
#[error("Invalid response format. Status code: {status_code}, Response body: {body}")]
InvalidResponseFormat {
status_code: u16,
body: String,
},
#[error("HTTP request error: {0}")]
ReqwestError(#[from] reqwest::Error),
#[error("BUG: {0}. Please report this issue.")]
BugError(String),
}