use oparl_types::namespace::ErrorNamespaceUrl;
use snafu::Snafu;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub))]
pub enum Error {
#[snafu(display("Entry not found"))]
NotFound,
#[snafu(display("Error interfacing with inventory backend"))]
Inventory {
source: Box<dyn std::error::Error + Send + Sync>,
},
}
impl Error {
pub const fn http_status_code(&self) -> u16 {
match self {
Error::NotFound => 404,
Error::Inventory { .. } => 500,
}
}
pub const fn is_not_found(&self) -> bool {
matches!(self, Self::NotFound)
}
}
impl From<Error> for oparl_types::Error {
fn from(value: Error) -> Self {
oparl_types::Error {
namespace: ErrorNamespaceUrl::Identifier,
message: value.to_string(),
debug: None,
extensions: serde_json::Map::new(),
}
}
}