Skip to content
This repository was archived by the owner on Oct 3, 2021. It is now read-only.

Only parse JSON response if http code is 200 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pdlwrapper/pdlwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import decimal
import requests
import time
import json


class Client:
Expand Down Expand Up @@ -33,12 +34,19 @@ def get_person(self, params):
params['api_key'] = self.pdl_api_key
resp = requests.get(self.PDL_URL, params=params)

resp_json = None
if resp.status_code == 200:
try:
resp_json = resp.json(parse_float=decimal.Decimal)
except json.JSONDecodeError:
pass

log_item = {
'partition_key': f'{self.env}_{self.account_id}',
'timestamp': int(round(time.time() * 1000000)),
'env': self.env,
'status_code': resp.status_code,
'response': resp.json(parse_float=decimal.Decimal)
'response': resp_json
}

self.dynamodb_table.put_item(Item=log_item)
Expand Down