-
Notifications
You must be signed in to change notification settings - Fork 132
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
Handle error thrown by urllib #1765
Conversation
e7a65dd
to
9285361
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Can we add a test for it by mocking the function that triggers BadStatusLine
? We have an example of how to mock an exception by using a side_effect
as seen below:
onadata/onadata/apps/api/tests/viewsets/test_charts_viewset.py
Lines 104 to 113 in fdd91d7
@mock.patch('onadata.libs.data.query._execute_query', | |
side_effect=raise_data_error) | |
def test_get_on_date_field_with_invalid_data(self, mock_execute_query): | |
data = {'field_name': 'date'} | |
request = self.factory.get('/charts', data) | |
force_authenticate(request, user=self.user) | |
response = self.view( | |
request, | |
pk=self.xform.id) | |
self.assertEqual(response.status_code, 400) |
9285361
to
54f3740
Compare
Added. |
54f3740
to
9f3c920
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
onadata/libs/utils/logger_tools.py
Outdated
return { | ||
'type': 'alert-error', | ||
'text': _(u'An error occured while trying to retrieve the form.') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would the action that would be required by the user to take if they encounter this error?
Would the error message in https://github.com/onaio/onadata/pull/1765/files#diff-018f1a90f318bf1748393be886fee2c0R502-R503 be sufficient in this case? If it would be sufficient could we add BadStatusLine
to except (BadStatusLine, MemoryError, OSError)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message would be perfect for this scenario. I'll update my PR.
- Add test
9f3c920
to
d96a644
Compare
Testing checks out @DavisRayM |
Changes / Features implemented
BadStatusLine
error raised when "a server responds with a HTTP status code that we don’t understand."Steps taken to verify this change does what is intended
test_error_raised_xform_url_upload_urllib_error
Side effects of implementing this change
N/A
Closes #1759