Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTPError handling when ReimbursementsURL doesn't exist #510

Conversation

luizfzs
Copy link
Contributor

@luizfzs luizfzs commented Jan 1, 2020

The issue happened when running Rosie on 2020-01-01. By the way the adapter.py works, it tries to fetch reimbursement files up to the year in which the application is running e.g. 2020. Since there is no such URL (at the time of this commit), the whole process fails due to an HTTPError 404.

By adding this handling, the reimbursements that cannot be found are skipped from the download process and the application runs without any issues.

What is the purpose of this Pull Request?
The goal of this PR is to add error handling to adapter.py when attempting to obtain a reimbursement that doesn't exist on the Chamber of Deputies website. If someone runs Rosie today (at least by the time this PR has been created), they are going to get an error when trying to obtain the reimbursement file for the year 2020. This error causes Rosie to completely stop.

What was done to achieve this purpose?
To handle the error, a try-except block was added on the update_reimbursements method, targeting only urllib.error.HTTPError and logging it with an ERROR level.

How to test if it really works?
Today, the fix can be tested by simply running Rosie, since there is no reimbursement file for the year of 2020.
An alternative way is by advancing the computer time to an year that there are no reimbursement URL to fetch, then running Rosie. Note that by doing this, you might get SSL errors due to the big gap between the clocks.

You should see a message similar to this:

YYYY-01-01 13:36:41,512 - rosie.chamber_of_deputies.adapter - ERROR - Could not update Reimbursements from year YYYY: HTTP Error 404: Not Found - https://www.camara.leg.br/cotas/Ano-YYYY.csv.zip

Who can help reviewing it?
Anyone

The issue happened when running Rosie on 2020-01-01. By the way the adapter.py works, it tries to fetch reimbursement files up to the year in which the application is running .e.g. 2020. Since there is no such URL (at the time of this commit), the whole process fails due to an HTTPError 404. 

By adding this handling, the reimbursements that cannot be found are skipped from the download process and the application runs without any issues.
Copy link
Collaborator

@sergiomario sergiomario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants