|
| 1 | +use std::error::Error; |
| 2 | +use std::fmt::{Display, Formatter}; |
| 3 | +use std::io; |
| 4 | +/// When there is an error while writing to VSS storage, the response contains a relevant error code. |
| 5 | +/// A mapping for VSS server error codes. Refer to [`ErrorResponse`] docs for more |
| 6 | +/// information regarding each error code and corresponding use-cases. |
| 7 | +/// |
| 8 | +/// [`ErrorResponse`]: crate::types::ErrorResponse |
| 9 | +#[derive(Debug)] |
| 10 | +pub enum VssError { |
| 11 | + /// Please refer to [`ErrorCode::NoSuchKeyException`]. |
| 12 | + /// |
| 13 | + /// [`ErrorCode::NoSuchKeyException`]: crate::types::ErrorCode::NoSuchKeyException |
| 14 | + NoSuchKeyError(String), |
| 15 | + |
| 16 | + /// Please refer to [`ErrorCode::InvalidRequestException`]. |
| 17 | + /// |
| 18 | + /// [`ErrorCode::InvalidRequestException`]: crate::types::ErrorCode::InvalidRequestException |
| 19 | + InvalidRequestError(String), |
| 20 | + |
| 21 | + /// Please refer to [`ErrorCode::ConflictException`]. |
| 22 | + /// |
| 23 | + /// [`ErrorCode::ConflictException`]: crate::types::ErrorCode::ConflictException |
| 24 | + ConflictError(String), |
| 25 | + |
| 26 | + /// Please refer to [`ErrorCode::AuthException`]. |
| 27 | + /// |
| 28 | + /// [`ErrorCode::AuthException`]: crate::types::ErrorCode::AuthException |
| 29 | + AuthError(String), |
| 30 | + |
| 31 | + /// Please refer to [`ErrorCode::InternalServerException`]. |
| 32 | + /// |
| 33 | + /// [`ErrorCode::InternalServerException`]: crate::types::ErrorCode::InternalServerException |
| 34 | + InternalServerError(String), |
| 35 | +} |
| 36 | + |
| 37 | +impl Display for VssError { |
| 38 | + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 39 | + match self { |
| 40 | + VssError::NoSuchKeyError(message) => { |
| 41 | + write!(f, "Requested key does not exist: {}", message) |
| 42 | + }, |
| 43 | + VssError::InvalidRequestError(message) => { |
| 44 | + write!(f, "Request sent to VSS was invalid: {}", message) |
| 45 | + }, |
| 46 | + VssError::ConflictError(message) => { |
| 47 | + write!(f, "Version conflict in write operation: {}", message) |
| 48 | + }, |
| 49 | + VssError::AuthError(message) => { |
| 50 | + write!(f, "Authentication or Authorization failure: {}", message) |
| 51 | + }, |
| 52 | + VssError::InternalServerError(message) => { |
| 53 | + write!(f, "InternalServerError: {}", message) |
| 54 | + }, |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +impl Error for VssError {} |
| 60 | + |
| 61 | +impl From<io::Error> for VssError { |
| 62 | + fn from(err: io::Error) -> Self { |
| 63 | + VssError::InternalServerError(err.to_string()) |
| 64 | + } |
| 65 | +} |
0 commit comments