oci_rust_sdk/core/
error.rs1pub type Result<T> = std::result::Result<T, OciError>;
3
4#[derive(Debug, thiserror::Error)]
6pub enum OciError {
7 #[error("HTTP request failed: {0}")]
9 HttpError(#[from] reqwest::Error),
10
11 #[error("Authentication failed: {0}")]
13 AuthError(String),
14
15 #[error("Serialization error: {0}")]
17 SerdeError(#[from] serde_json::Error),
18
19 #[error("Service error {status}: {message}")]
21 ServiceError {
22 status: u16,
23 code: String,
24 message: String,
25 },
26
27 #[error("Configuration error: {0}")]
29 ConfigError(String),
30
31 #[error("I/O error: {0}")]
33 IoError(#[from] std::io::Error),
34
35 #[error("Invalid region: {0}")]
37 InvalidRegion(String),
38
39 #[error("RSA signing error: {0}")]
41 SigningError(String),
42
43 #[error("{0}")]
45 Other(String),
46}
47
48impl OciError {
49 pub fn is_retryable(&self) -> bool {
51 match self {
52 OciError::ServiceError { status: 429, .. } => true,
54 OciError::ServiceError { status, .. } if *status >= 500 => true,
56 OciError::HttpError(_) => true,
58 _ => false,
60 }
61 }
62
63 pub fn from_response(status: u16, code: String, message: String) -> Self {
65 OciError::ServiceError {
66 status,
67 code,
68 message,
69 }
70 }
71}
72
73#[derive(Debug, serde::Deserialize)]
75pub struct ServiceErrorResponse {
76 pub code: String,
77 pub message: String,
78}