use bevy::prelude::*;
use serde::{Serialize, Deserialize};
use crate::BusEvent;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum EventBusErrorType {
Serialization, Connection, NotConfigured, Topic, Timeout, DeliveryFailure, Deserialization, ConsumerError, Other, }
#[derive(Event, Debug, Clone)]
pub struct EventBusError<T: BusEvent> {
pub topic: String,
pub error_type: EventBusErrorType,
pub error_message: String,
pub timestamp: std::time::SystemTime,
pub original_event: Option<T>,
pub backend: Option<String>,
pub partition: Option<i32>,
pub offset: Option<i64>,
}
impl<T: BusEvent> EventBusError<T> {
pub fn immediate(
topic: String,
error_type: EventBusErrorType,
error_message: String,
original_event: T,
) -> Self {
Self {
topic,
error_type,
error_message,
timestamp: std::time::SystemTime::now(),
original_event: Some(original_event),
backend: None,
partition: None,
offset: None,
}
}
pub fn async_delivery(
topic: String,
error_message: String,
backend: Option<String>,
partition: Option<i32>,
offset: Option<i64>,
) -> Self {
Self {
topic,
error_type: EventBusErrorType::DeliveryFailure,
error_message,
timestamp: std::time::SystemTime::now(),
original_event: None,
backend,
partition,
offset,
}
}
}
#[derive(Event, Debug, Clone)]
pub struct EventBusDecodeError {
pub topic: String,
pub error_message: String,
pub timestamp: std::time::SystemTime,
pub raw_payload: Vec<u8>,
pub decoder_name: String,
pub partition: Option<i32>,
pub offset: Option<i64>,
}
impl EventBusDecodeError {
pub fn new(
topic: String,
error_message: String,
raw_payload: Vec<u8>,
decoder_name: String,
partition: Option<i32>,
offset: Option<i64>,
) -> Self {
Self {
topic,
error_message,
timestamp: std::time::SystemTime::now(),
raw_payload,
decoder_name,
partition,
offset,
}
}
}