use bevy::prelude::*;
use bevy_event_bus::BusEvent;
use bevy_event_bus::resources::MessageMetadata;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum EventBusErrorType {
Serialization, Connection, NotConfigured, Topic, Timeout, DeliveryFailure, Deserialization, ConsumerError, InvalidReadConfig, InvalidWriteConfig, Other, }
#[derive(Message, 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 metadata: Option<MessageMetadata>,
}
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,
metadata: None,
}
}
pub fn async_delivery(
topic: String,
error_message: String,
backend: Option<String>,
metadata: Option<MessageMetadata>,
) -> Self {
Self {
topic,
error_type: EventBusErrorType::DeliveryFailure,
error_message,
timestamp: std::time::SystemTime::now(),
original_event: None,
backend,
metadata,
}
}
}
#[derive(Message, 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 metadata: Option<MessageMetadata>,
}
impl EventBusDecodeError {
pub fn new(
topic: String,
error_message: String,
raw_payload: Vec<u8>,
decoder_name: String,
metadata: Option<MessageMetadata>,
) -> Self {
Self {
topic,
error_message,
timestamp: std::time::SystemTime::now(),
raw_payload,
decoder_name,
metadata,
}
}
}