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

fix: construct InfluxDBError without http response #375

Merged
merged 2 commits into from
Dec 6, 2021
Merged
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 1.25.0 [unreleased]

### Bug Fixes
1. [#375](https://github.com/influxdata/influxdb-client-python/pull/375): Construct `InfluxDBError` without HTTP response

### CI
1. [#54](https://github.com/influxdata/influxdb-client-python/pull/370): Add Python 3.10 to CI builds
1. [#370](https://github.com/influxdata/influxdb-client-python/pull/370): Add Python 3.10 to CI builds

## 1.24.0 [2021-11-26]

### Features
Expand Down
11 changes: 8 additions & 3 deletions influxdb_client/client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ class InfluxDBError(Exception):

def __init__(self, response: HTTPResponse):
"""Initialize the InfluxDBError handler."""
self.response = response
self.message = self._get_message(response)
self.retry_after = response.getheader('Retry-After')
if response is not None:
self.response = response
self.message = self._get_message(response)
self.retry_after = response.getheader('Retry-After')
else:
self.response = None
self.message = 'no response'
self.retry_after = None
super().__init__(self.message)

def _get_message(self, response):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_InfluxDBError.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ def test_message_get_retry_after(self):
influx_db_error = InfluxDBError(response=HTTPResponse(reason="too many requests"))
self.assertEqual("too many requests", str(influx_db_error))
self.assertEqual(None, influx_db_error.retry_after)

def test_no_response(self):
influx_db_error = InfluxDBError(response=None)
self.assertEqual("no response", str(influx_db_error))
self.assertIsNone(influx_db_error.response)
self.assertIsNone(influx_db_error.retry_after)