rusty_box/client/
client_error.rs1use std::fmt;
2
3use crate::auth::auth_errors::AuthError;
4
5use super::client_error_model::BoxAPIErrorResponse;
6
7#[derive(Debug, Clone)]
8pub struct ResponseContent<T> {
9 pub status: reqwest::StatusCode,
10 pub content: String,
11 pub entity: Option<T>,
12}
13
14pub enum BoxAPIError {
16 Network(reqwest::Error),
17 Serde(serde_json::Error),
18 Io(std::io::Error),
19 ResponseError(BoxAPIErrorResponse),
20 AuthError(AuthError),
21}
22
23impl fmt::Display for BoxAPIErrorResponse {
24 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25 write!(f, "APIError {{ object_type: {:?}, status: {:?}, code: {:?}, message: {:?}, context_info: {:?}, help_url: {:?}, request_id: {:?} }}", self.object_type, self.status, self.code, self.message, self.context_info, self.help_url, self.request_id)
26 }
27}
28
29impl fmt::Display for BoxAPIError {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 let (module, e) = match self {
32 BoxAPIError::Network(e) => ("reqwest", e.to_string()),
33 BoxAPIError::Serde(e) => ("serde", e.to_string()),
34 BoxAPIError::Io(e) => ("IO", e.to_string()),
35 BoxAPIError::ResponseError(e) => ("Box API Error", e.to_string()),
36 BoxAPIError::AuthError(e) => ("Box Auth Error", e.to_string()),
37 };
38 write!(f, "error in {}: {}", module, e)
39 }
40}
41impl fmt::Debug for BoxAPIError {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 let (module, e) = match self {
44 BoxAPIError::Network(e) => ("reqwest", e.to_string()),
45 BoxAPIError::Serde(e) => ("serde", e.to_string()),
46 BoxAPIError::Io(e) => ("IO", e.to_string()),
47 BoxAPIError::ResponseError(e) => ("Box API Error", e.to_string()),
48 BoxAPIError::AuthError(e) => ("Box Auth Error", e.to_string()),
49 };
50 write!(f, "error in {}: {}", module, e)
51 }
52}
53
54impl From<reqwest::Error> for BoxAPIError {
55 fn from(e: reqwest::Error) -> Self {
56 BoxAPIError::Network(e)
57 }
58}
59
60impl From<serde_json::Error> for BoxAPIError {
61 fn from(e: serde_json::Error) -> Self {
62 BoxAPIError::Serde(e)
63 }
64}
65
66impl From<std::io::Error> for BoxAPIError {
67 fn from(e: std::io::Error) -> Self {
68 BoxAPIError::Io(e)
69 }
70}
71impl From<BoxAPIErrorResponse> for BoxAPIError {
72 fn from(e: BoxAPIErrorResponse) -> Self {
73 BoxAPIError::ResponseError(e)
74 }
75}
76
77impl From<AuthError> for BoxAPIError {
78 fn from(e: AuthError) -> Self {
79 BoxAPIError::AuthError(e)
80 }
81}
82
83