Skip to content

Commit

Permalink
Merge pull request #55 from nationalarchives/better-rollbar-error
Browse files Browse the repository at this point in the history
Better rollbar errors
  • Loading branch information
dragon-dxw authored Feb 7, 2023
2 parents d86aa76 + cf69ade commit b6ce02f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
Expand Down
16 changes: 12 additions & 4 deletions ds-caselaw-ingester/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
rollbar.init(os.getenv("ROLLBAR_TOKEN"), environment=os.getenv("ROLLBAR_ENV"))


class S3HTTPError(Exception):
pass


class FileNotFoundException(Exception):
pass

Expand Down Expand Up @@ -318,15 +322,19 @@ def handler(event, context):
# Retrieve tar file from S3
http = urllib3.PoolManager()
try:
file = http.request("GET", message["s3-folder-url"])
except:
s3_response = http.request("GET", message["s3-folder-url"])
tar_gz_contents = s3_response.data
if s3_response.status < 400:
raise S3HTTPError(tar_gz_contents)
except Exception:
# Send retry message to sqs if the GET fails
send_retry_message(message, sqs_client)

raise
# Store it in the /tmp directory
filename = os.path.join("/tmp", f"{consignment_reference}.tar.gz")

with open(filename, "wb") as out:
out.write(file.data)
out.write(tar_gz_contents)
out.close()

tar = tarfile.open(filename, mode="r")
Expand Down

0 comments on commit b6ce02f

Please sign in to comment.