use anyhow::Error;
pub fn codes(error: &Error) -> impl Iterator<Item = String> + '_ {
error.chain().filter_map(|cause| {
cause
.to_string()
.strip_prefix("error ")
.and_then(|rest| rest.split_whitespace().next())
.map(str::to_string)
})
}
pub fn code(error: &Error) -> Option<String> {
codes(error).next()
}
pub fn has_code(error: &Error, expected: &str) -> bool {
codes(error).any(|code| code == expected)
}
pub fn is_stale(error: &Error) -> bool {
error.is::<crate::sync::seed_claim::membership::StaleContext>()
}
pub fn is_access_refusal(error: &Error) -> bool {
has_code(error, "sync-server-refused")
|| has_code(error, "enrollment-unauthorized")
|| has_code(error, "enrollment-revoked")
|| has_code(error, "sync-device-removed")
}