"""Interface for the ows-account microservice.""" from owsresponse import response from owsrequest import request as requests from sentry_sdk import capture_message from features.constants import error from features.constants import services def get_subaccount_info(subaccount_id): """Get data for a subaccount. Args: subaccount_id: the ID of the subaccount Returns: Response: a response object """ account_response = requests.get( services.OWS_ACCOUNT, '/subaccount/{}'.format(subaccount_id) ) if account_response.status_code == 200: return response.Response(message=account_response.json()) if account_response.status_code == 404: return response.create_error_response( status=400, code=error.ERROR_CODE_SUBACCOUNT_DOES_NOT_EXIST, message=error.ERROR_MESSAGE_SUBACCOUNT_DOES_NOT_EXIST, ) error_message = '{ows_account} returns {code} status'.format( ows_account=services.OWS_ACCOUNT, code=account_response.status_code ) capture_message(error_message) return response.create_fatal_response()