Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Unreleased changes
* bugfix: `validate` and `send` could incorrect number of total records
* bugfix: failed `send` could bury error message coming from ODS
* bugfix: `validate` and `send` could show incorrect number of total records

### v0.1.6
<details>
Expand Down
23 changes: 16 additions & 7 deletions lightbeam/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def do_post(self, endpoint, file_name, data, line_number, data_hash):
ssl=self.lightbeam.config["connection"]["verify_ssl"],
headers=self.lightbeam.api.headers
) as response:
body = await response.text()
text = await response.text()
status = response.status
if status!=401:
# update status_counts (for every-second status update)
Expand All @@ -156,20 +156,29 @@ async def do_post(self, endpoint, file_name, data, line_number, data_hash):

# warn about errors
if response.status not in [ 200, 201 ]:
message = str(response.status) + ": " + util.linearize(json.loads(body).get("message"))
try:
body = json.loads(text)
if "errors" in body:
log_message = str(response.status) + ": " + "; ".join(map(util.linearize, body["errors"]))
elif "message" in body:
log_message = str(response.status) + ": " + util.linearize(body["message"])
else:
log_message = ""
except json.decoder.JSONDecodeError:
log_message = ""

# update run metadata...
failures = self.lightbeam.metadata["resources"][endpoint].get("failures", [])
do_append = True
for index, item in enumerate(failures):
if item["status_code"]==response.status and item["message"]==message and item["file"]==file_name:
if item["status_code"]==response.status and item["message"]==log_message and item["file"]==file_name:
failures[index]["line_numbers"].append(line_number)
failures[index]["count"] += 1
do_append = False
if do_append:
failure = {
'status_code': response.status,
'message': message,
'message': log_message,
'file': file_name,
'line_numbers': [line_number],
'count': 1
Expand All @@ -178,9 +187,9 @@ async def do_post(self, endpoint, file_name, data, line_number, data_hash):
self.lightbeam.metadata["resources"][endpoint]["failures"] = failures

# update output and counters
self.lightbeam.increment_status_reason(message)
self.lightbeam.increment_status_reason(log_message)
if response.status==400:
raise Exception(message)
raise ValueError(log_message)
else:
self.lightbeam.num_errors += 1

Expand All @@ -206,7 +215,7 @@ async def do_post(self, endpoint, file_name, data, line_number, data_hash):

except RuntimeError as e:
await asyncio.sleep(1)
except Exception as e:
except ValueError as e:
status = 400
self.lightbeam.num_errors += 1
self.logger.warn("{0} (at line {1} of {2} )".format(str(e), line_number, file_name))
Expand Down