Add HTTPError handling when ReimbursementsURL doesn't exist #510
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 anHTTPError 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 theupdate_reimbursements
method, targeting onlyurllib.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:
Who can help reviewing it?
Anyone