from Services.Redis.Actions.actions import RedisActions from ApiLayers.AllConfigs.Redis.configs import RedisValidationKeys class HTTPExceptionApi(Exception): def __init__(self, error_code: str, lang: str, loc: str = "", sys_msg: str = ""): """ Initialize the HTTPExceptionApi class. :param error_code: The error code. To retrieve the error message. :param lang: The language. Catch error msg from redis. :param loc: The location. To log where error occurred. :param sys_msg: The system message. To log the error message. """ self.error_code = error_code self.lang = lang self.loc = loc self.sys_msg = sys_msg def retrieve_error_message_by_code_at_redis(self): """ Retrieve the error message from the redis by the error code. """ error_redis_key = ( f"{RedisValidationKeys.LANGUAGE_MODELS}:{RedisValidationKeys.ERRORCODES}" ) error_message = RedisActions.get_json(list_keys=[error_redis_key, self.lang]) if error_message.status: error_message_dict = error_message.first.as_dict if error_message_dict.get(self.error_code, None): return error_message_dict.get(self.error_code) return f"System Message -> {self.sys_msg}"