use std::fmt;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use crate::ProviderId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum VerificationErrorKind {
Configuration,
Transport,
Timeout,
InvalidResponse,
NotImplemented,
}
impl fmt::Display for VerificationErrorKind {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let value = match self {
Self::Configuration => "configuration",
Self::Transport => "transport",
Self::Timeout => "timeout",
Self::InvalidResponse => "invalid_response",
Self::NotImplemented => "not_implemented",
};
formatter.write_str(value)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[error("{provider} verification failed ({kind}): {message}")]
pub struct VerificationError {
pub provider: ProviderId,
pub kind: VerificationErrorKind,
pub message: String,
}
impl VerificationError {
pub fn new(
provider: ProviderId,
kind: VerificationErrorKind,
message: impl Into<String>,
) -> Self {
Self {
provider,
kind,
message: message.into(),
}
}
}