"""Interface to the ows-track microservice.""" from oto import response from owsrequest import request from sentry_sdk import capture_exception from product_workflow.constants import error, services def get_tracks_by_product_id(product_id): """Get tracks for a product. Args: product_id (int): unique identifier for the product Returns: response.Response: response object containing track data """ try: ows_track_response = request.get( services.OWS_TRACK, '/product/{product_id}/tracks'.format(product_id=product_id)) response_body = ows_track_response.json() if ows_track_response.status_code != 200: return response.create_error_response( status=ows_track_response.status_code, code=response_body.get('code'), message=response_body.get('message')) return response.Response(message=response_body) except Exception: capture_exception() return response.create_error_response( status=500, code=error.INTERNAL_ERROR, message='Error while fetching tracks by product id')