"""Lambda product-participations-check function module.""" from lambdacommon.common_config import logger from src.logic.check_ddex_generation import check_ddex_generation from src.logic.check_ddex_generation import DDEX_ERROR from src.logic.check_ddex_generation import DDEX_UNKNOWN class DDEXCheckException(Exception): """DDEXCheckException class.""" pass class DDEXCheckUnknown(Exception): """DDEXCheckUnkown retriable class.""" pass def handler(event, context): """Lambda entry point.""" try: upc = event['upc'] ddex_result, ddex_info = check_ddex_generation(upc) if ddex_result == DDEX_ERROR: logger.error(f'{ddex_result} for UPC {upc}, with error: {ddex_info}') raise DDEXCheckException(f'DDEX Check failed: {ddex_info}') if ddex_result == DDEX_UNKNOWN: logger.warning('DDEX response was empty or unknown and it should be retried.') raise DDEXCheckUnknown(f'Unknown or empty DDEX response. {ddex_info}') logger.info(f'DDEX Check for UPC: {upc} finished with {ddex_result}: {ddex_info}') return { 'status': 'OK', 'DDEX_CHECK_RESULT': ddex_result, 'DDEX_CHECK_INFO': ddex_info } except Exception as e: logger.exception(str(e)) raise e