Gemention/src/error.rs

37 lines
814 B
Rust

use std::str::Utf8Error;
use async_trait::async_trait;
use fluffer::GemBytes;
use thiserror::Error;
#[derive(Error, Debug)]
pub(crate) enum GementionError {
#[error("No content found for target")]
NoContentFoundForTarget,
#[error("Not a Titan resource")]
NotTitanResource,
#[error("Invalid body")]
InvalidBody,
#[error("Gemention Target not provided")]
TargetNotProvided,
#[error("url parsing error: {0}")]
UrlParsingError(#[from] url::ParseError),
#[error("value was not utf8: {0}")]
Utf8Error(#[from] Utf8Error),
#[error("generic error: {0}")]
UnclassifiedError(#[from] anyhow::Error),
}
#[async_trait]
impl GemBytes for GementionError {
async fn gem_bytes(self) -> Vec<u8> {
format!("59 text/gemini\r\n{}", self).into_bytes()
}
}