integrate some std io error kinds with our status code abstraction
associate rocksdb error kinds with std io error kinds Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
7c8eeaf4ea
commit
b56e480b3c
3 changed files with 39 additions and 2 deletions
|
@ -178,6 +178,7 @@ impl Error {
|
|||
| Self::FeatureDisabled(..) => response::bad_request_code(&self.kind()),
|
||||
| Self::Reqwest(error) => error.status().unwrap_or(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
| Self::Conflict(_) => StatusCode::CONFLICT,
|
||||
| Self::Io(error) => response::io_error_code(error.kind()),
|
||||
| _ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,3 +95,17 @@ pub(super) fn ruma_error_message(error: &ruma::api::client::error::Error) -> Str
|
|||
pub(super) fn ruma_error_kind(e: &ruma::api::client::error::Error) -> &ErrorKind {
|
||||
e.error_kind().unwrap_or(&ErrorKind::Unknown)
|
||||
}
|
||||
|
||||
pub(super) fn io_error_code(kind: std::io::ErrorKind) -> StatusCode {
|
||||
use std::io::ErrorKind;
|
||||
|
||||
match kind {
|
||||
| ErrorKind::InvalidInput => StatusCode::BAD_REQUEST,
|
||||
| ErrorKind::PermissionDenied => StatusCode::FORBIDDEN,
|
||||
| ErrorKind::NotFound => StatusCode::NOT_FOUND,
|
||||
| ErrorKind::TimedOut => StatusCode::GATEWAY_TIMEOUT,
|
||||
| ErrorKind::FileTooLarge => StatusCode::PAYLOAD_TOO_LARGE,
|
||||
| ErrorKind::StorageFull => StatusCode::INSUFFICIENT_STORAGE,
|
||||
| _ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue