use h3::error::{ConnectionError, StreamError};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum H3Error {
#[error("h3 connection error: {0}")]
Connection(#[from] ConnectionError),
#[error("h3 stream error: {0}")]
Stream(#[from] StreamError),
#[error("cancelled")]
Cancelled,
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
}
impl H3Error {
#[must_use]
pub fn is_cancelled(&self) -> bool {
matches!(self, Self::Cancelled)
}
}
impl From<crate::error::Error> for H3Error {
fn from(err: crate::error::Error) -> Self {
if err.is_cancelled() {
Self::Cancelled
} else {
Self::Io(std::io::Error::other(err.to_string()))
}
}
}
#[cfg(test)]
mod tests {
use super::H3Error;
use crate::error::Error;
use crate::types::CancelReason;
#[test]
fn cancelled_error_maps() {
let err = Error::cancelled(&CancelReason::user("test"));
let mapped = H3Error::from(err);
assert!(mapped.is_cancelled());
}
}