use std::backtrace::Backtrace;
use std::error::Error as StdError;
#[cfg(feature = "async")]
use async_trait::async_trait;
#[cfg(feature = "async")]
#[async_trait]
pub trait AsyncForgeError: StdError + Send + Sync + 'static {
fn kind(&self) -> &'static str;
fn caption(&self) -> &'static str;
fn is_retryable(&self) -> bool {
false
}
fn is_fatal(&self) -> bool {
false
}
fn status_code(&self) -> u16 {
500
}
fn exit_code(&self) -> i32 {
1
}
fn user_message(&self) -> String {
self.to_string()
}
fn dev_message(&self) -> String {
format!("[{}] {}", self.kind(), self)
}
fn backtrace(&self) -> Option<&Backtrace> {
None
}
async fn async_handle(&self) -> Result<(), Box<dyn StdError + Send + Sync>>;
fn register(&self) {
crate::macros::call_error_hook(
self.caption(),
self.kind(),
self.is_fatal(),
self.is_retryable(),
);
}
}
#[cfg(feature = "async")]
pub type AsyncResult<T, E> = std::result::Result<T, E>;