From 1efc25ac15dfd1dd665a408178336502beb00962 Mon Sep 17 00:00:00 2001 From: Philip Wafula Date: Wed, 19 May 2021 16:25:10 +0000 Subject: [PATCH] Refactors to handle error in metadata handling --- apps/cic-ussd/cic_ussd/metadata/base.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/cic-ussd/cic_ussd/metadata/base.py b/apps/cic-ussd/cic_ussd/metadata/base.py index 3db80d43..a60538de 100644 --- a/apps/cic-ussd/cic_ussd/metadata/base.py +++ b/apps/cic-ussd/cic_ussd/metadata/base.py @@ -102,7 +102,7 @@ class MetadataRequestsHandler(Metadata): 'digest': json.loads(data).get('digest'), } } - formatted_data = json.dumps(formatted_data).encode('utf-8') + formatted_data = json.dumps(formatted_data) result = make_request(method='PUT', url=self.url, data=formatted_data, headers=self.headers) logg.info(f'signed metadata submission status: {result.status_code}.') metadata_http_error_handler(result=result) @@ -116,8 +116,10 @@ class MetadataRequestsHandler(Metadata): """This function is responsible for querying the metadata server for data corresponding to a unique pointer.""" result = make_request(method='GET', url=self.url) metadata_http_error_handler(result=result) - response_data = result.content - data = json.loads(response_data.decode('utf-8')) + response_data = result.json() + data = json.loads(response_data) + if not isinstance(data, dict): + raise ValueError(f'Invalid data object: {data}.') if result.status_code == 200 and self.cic_type == ':cic.person': person = Person() deserialized_person = person.deserialize(person_data=data)