from typing import Dict, Any, Callable from charts_push_messages.schemas import FeedMessageCreatedSchema, FeedMessageCreatedWithDataSchema def get_feed_message_created(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}" def get_feed_message_with_data(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}" DESERIALIZING_LOGGER_MESSAGES = { str(FeedMessageCreatedSchema()): get_feed_message_created, str(FeedMessageCreatedWithDataSchema()): get_feed_message_with_data } def get_deserializing_logger_message(schema) -> Callable: """Get logger message based on a passed Marshmallow Schema Args: schema: Instance of a Marshmallow schema """ return DESERIALIZING_LOGGER_MESSAGES[str(schema)]