implement the new type property for the system error

This commit is contained in:
Tamo 2023-01-05 21:06:50 +01:00
parent ce3e8794a2
commit 0646f63404
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69
1 changed files with 9 additions and 3 deletions

View File

@ -95,6 +95,7 @@ enum ErrorType {
InternalError,
InvalidRequestError,
AuthenticationError,
System,
}
impl fmt::Display for ErrorType {
@ -105,6 +106,7 @@ impl fmt::Display for ErrorType {
InternalError => write!(f, "internal"),
InvalidRequestError => write!(f, "invalid_request"),
AuthenticationError => write!(f, "auth"),
System => write!(f, "system"),
}
}
}
@ -240,12 +242,12 @@ impl Code {
match self {
// related to the setup
IoError => ErrCode::invalid("io_error", StatusCode::UNPROCESSABLE_ENTITY),
IoError => ErrCode::system("io_error", StatusCode::UNPROCESSABLE_ENTITY),
TooManyOpenFiles => {
ErrCode::invalid("too_many_open_files", StatusCode::UNPROCESSABLE_ENTITY)
ErrCode::system("too_many_open_files", StatusCode::UNPROCESSABLE_ENTITY)
}
NoSpaceLeftOnDevice => {
ErrCode::invalid("no_space_left_on_device", StatusCode::UNPROCESSABLE_ENTITY)
ErrCode::system("no_space_left_on_device", StatusCode::UNPROCESSABLE_ENTITY)
}
// index related errors
@ -531,6 +533,10 @@ impl ErrCode {
fn invalid(error_name: &'static str, status_code: StatusCode) -> ErrCode {
ErrCode { status_code, error_name, error_type: ErrorType::InvalidRequestError }
}
fn system(error_name: &'static str, status_code: StatusCode) -> ErrCode {
ErrCode { status_code, error_name, error_type: ErrorType::System }
}
}
impl ErrorCode for JoinError {