from typing import Dict, Any, Callable from charts_feed_messages.schemas import IncomingEvent, MessageEventWithData def get_event_with_data_schema_logger_message(data: Dict[str, Any], err: Dict[str, Any]) -> str: """Get custom logger message when deserializing Basic Message got from User Data Api""" return f"{data['message_id']} - Message id of " \ f"- {data['event_id']} - Event id has invalid structure of event: {err}" def get_incoming_event_schema_logger_message(data: Dict[str, Any], err: Dict[str, Any]): """Get custom logger message when deserializing Incoming Event""" return f"{data['id']} id Event has invalid structure of event: {err}" DESERIALIZING_LOGGER_MESSAGES = { str(MessageEventWithData()): get_event_with_data_schema_logger_message, str(IncomingEvent()): get_incoming_event_schema_logger_message } def get_event_schema_logger_message_builder(schema) -> Callable: """Get logger message based on a Marshmallow schema to deserialize the object Args: schema: Instance of a Marshmallow schema """ return DESERIALIZING_LOGGER_MESSAGES[str(schema)]