d6dc02f
use std::fmt;
#[derive(Debug)]
pub enum PushError {
/// 配置不合法:缺密钥、密钥不成对、subject 格式错误等。
Config(String),
/// 订阅数据本身坏掉了(endpoint/密钥解析失败),该订阅不可修复。
Subscription(String),
/// 推送服务或网络层的暂时性失败。
Transport(String),
Internal(String),
}
impl fmt::Display for PushError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Config(msg) => write!(f, "push config error: {msg}"),
Self::Subscription(msg) => write!(f, "push subscription error: {msg}"),
Self::Transport(msg) => write!(f, "push transport error: {msg}"),
Self::Internal(msg) => write!(f, "push internal error: {msg}"),
}
}
}
impl std::error::Error for PushError {}
impl From<web_push_native::Error> for PushError {
fn from(error: web_push_native::Error) -> Self {
Self::Internal(error.to_string())
}
}