jquants_api_client/
error.rs1use serde::Deserialize;
4use thiserror::Error;
5
6use crate::api::shared::responses::error_response::JQuantsErrorResponse;
7
8#[derive(Debug, Deserialize)]
10pub struct ErrorResponse {
11 pub status_code: u16,
13 pub error_message: String,
15}
16
17impl std::fmt::Display for ErrorResponse {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 write!(
20 f,
21 "Status code: {}, Error message: {}",
22 self.status_code, self.error_message
23 )
24 }
25}
26
27impl std::error::Error for ErrorResponse {}
28
29#[derive(Error, Debug)]
32pub enum JQuantsError {
33 #[error("Invalid credentials provided. Status code: {status_code}, Body: {body}")]
35 InvalidCredentials {
36 status_code: u16,
38
39 body: JQuantsErrorResponse,
41 },
42
43 #[error("ID token is invalid or expired. Status code: {status_code}, Message: {body}")]
45 IdTokenInvalidOrExpired {
46 status_code: u16,
48
49 body: JQuantsErrorResponse,
51 },
52
53 #[error("API error occurred. Status code: {status_code}, Message: {body}")]
55 ApiError {
56 status_code: u16,
58
59 body: JQuantsErrorResponse,
61 },
62
63 #[error("Invalid response format. Status code: {status_code}, Response body: {body}")]
65 InvalidResponseFormat {
66 status_code: u16,
68
69 body: String,
71 },
72
73 #[error("HTTP request error: {0}")]
75 ReqwestError(#[from] reqwest::Error),
76
77 #[error("BUG: {0}. Please report this issue.")]
79 BugError(String),
80}