"""Interface for the ows-track microservice.""" from owsrequest import request from sound_recordings.constants import service_name class BadGateway(Exception): """Downstream from ows-track exception.""" pass def claim_isrc(): """Claim new ISRC.""" claim_new_isrc_response = request.post( service_name.OWS_TRACK, '/claim_new_isrc') status_code = claim_new_isrc_response.status_code if status_code in (502, 504): raise BadGateway() elif status_code not in (200, 201, 204): raise Exception(f'Unable to claim an isrc. HTTP {status_code} from ows-track') return claim_new_isrc_response.json()['isrc']