pub type Result<T, E = JsonLdError> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
pub enum JsonLdError {
#[error("invalid JSON: {0}")]
Json(String),
#[error("JSON-LD error ({code}): {message}")]
JsonLd { code: String, message: String },
#[error("loading remote context failed: {0}")]
ContextNotFound(String),
#[error("the document has no key ({0})")]
MissingKey(String),
#[error("invalid graph name: {0}")]
InvalidGraphName(String),
#[error("a graph of this document is already owned by another document: {0}")]
GraphOwned(String),
#[error("document too large for one atomic request: {statements} statements (backend limit {limit})")]
DocumentTooLarge { statements: usize, limit: usize },
#[error("invalid document: {0}")]
Invalid(String),
#[error(transparent)]
Store(#[from] oxilite_core::Error),
}
impl JsonLdError {
pub fn from_store(e: oxilite_core::Error) -> Self {
let msg = e.to_string();
if msg.contains("jsonld_graphs.g") {
Self::GraphOwned(msg)
} else {
Self::Store(e)
}
}
pub fn code(&self) -> Option<&str> {
match self {
Self::JsonLd { code, .. } => Some(code),
Self::ContextNotFound(_) => Some("loading remote context failed"),
_ => None,
}
}
}