Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273use knot_wire::WireError;
#[derive(Debug, Clone)]pub enum KnotError { Wire(WireError),}
impl KnotError { pub fn internal(message: impl Into<String>) -> Self { KnotError::Wire(WireError::internal(message)) }
pub fn upstream(message: impl Into<String>) -> Self { KnotError::Wire(WireError::upstream_unavailable(message)) }
pub fn into_wire(self) -> WireError { match self { KnotError::Wire(error) => error, } }}
impl std::fmt::Display for KnotError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { KnotError::Wire(error) => error.fmt(f), } }}
impl From<WireError> for KnotError { fn from(error: WireError) -> Self { KnotError::Wire(error) }}
impl From<worker::Error> for KnotError { fn from(error: worker::Error) -> Self { KnotError::internal(error.to_string()) }}
impl From<knot_atproto::AtprotoError> for KnotError { fn from(error: knot_atproto::AtprotoError) -> Self { use knot_atproto::AtprotoError; if error.is_transient() { return KnotError::Wire(WireError::upstream_unavailable(error.to_string())); } match error { AtprotoError::Resolve(_) => { KnotError::Wire(WireError::invalid_request(error.to_string())) } AtprotoError::PlcSubmit { .. } => { KnotError::Wire(WireError::bad_gateway(error.to_string())) } other => KnotError::internal(other.to_string()), } }}
impl From<knot_artifacts::ArtifactsError> for KnotError { fn from(error: knot_artifacts::ArtifactsError) -> Self { use knot_artifacts::ArtifactsError; match error { ArtifactsError::AlreadyExists(message) => KnotError::Wire(WireError::conflict(message)), ArtifactsError::NotFound(message) => KnotError::Wire(WireError::not_found(message)), ArtifactsError::Upstream(message) => KnotError::upstream(message), ArtifactsError::Binding(message) => KnotError::internal(message), } }}