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