use alloc::borrow::Cow;
use super::core::AppError;
use crate::AppErrorKind;
impl AppError {
pub fn not_found(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::NotFound, msg)
}
pub fn validation(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Validation, msg)
}
pub fn unauthorized(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Unauthorized, msg)
}
pub fn forbidden(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Forbidden, msg)
}
pub fn conflict(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Conflict, msg)
}
pub fn bad_request(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::BadRequest, msg)
}
pub fn rate_limited(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::RateLimited, msg)
}
pub fn telegram_auth(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::TelegramAuth, msg)
}
pub fn internal(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Internal, msg)
}
pub fn service(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Service, msg)
}
pub fn database(msg: Option<Cow<'static, str>>) -> Self {
let err = Self::new_raw(AppErrorKind::Database, msg);
err.emit_telemetry();
err
}
pub fn database_with_message(msg: impl Into<Cow<'static, str>>) -> Self {
Self::database(Some(msg.into()))
}
pub fn config(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Config, msg)
}
pub fn turnkey(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Turnkey, msg)
}
pub fn timeout(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Timeout, msg)
}
pub fn network(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Network, msg)
}
pub fn dependency_unavailable(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::DependencyUnavailable, msg)
}
pub fn service_unavailable(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::DependencyUnavailable, msg)
}
pub fn serialization(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Serialization, msg)
}
pub fn deserialization(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Deserialization, msg)
}
pub fn external_api(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::ExternalApi, msg)
}
pub fn queue(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Queue, msg)
}
pub fn cache(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Cache, msg)
}
}