Implement ErrorCode on the heed Error

This commit is contained in:
Kerollmops 2022-10-04 11:07:14 +02:00 committed by Clément Renault
parent 91e13c2824
commit c70f375669
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 18 additions and 0 deletions

View File

@ -2,6 +2,7 @@ use std::collections::BTreeMap;
use actix_web::web::Data;
use actix_web::{web, HttpRequest, HttpResponse};
use index::{Settings, Unchecked};
use index_scheduler::{IndexScheduler, Query, Status};
use log::debug;
use serde::{Deserialize, Serialize};

View File

@ -2,6 +2,7 @@ use std::fmt;
use actix_web::{self as aweb, http::StatusCode, HttpResponseBuilder};
use aweb::rt::task::JoinError;
use milli::heed::{Error as HeedError, MdbError};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
@ -392,6 +393,22 @@ impl ErrorCode for milli::Error {
}
}
impl ErrorCode for HeedError {
fn error_code(&self) -> Code {
match self {
HeedError::Mdb(MdbError::MapFull) => Code::DatabaseSizeLimitReached,
HeedError::Mdb(MdbError::Invalid) => Code::InvalidStore,
HeedError::Io(_)
| HeedError::Mdb(_)
| HeedError::Encoding
| HeedError::Decoding
| HeedError::InvalidDatabaseTyping
| HeedError::DatabaseClosing
| HeedError::BadOpenOptions => Code::Internal,
}
}
}
#[cfg(feature = "test-traits")]
mod strategy {
use proptest::strategy::Strategy;