Skip to content

Commit fb2c3b0

Browse files
committed
chore: use InfluxDBError instead ApiException
1 parent 9712d1d commit fb2c3b0

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

README.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -1178,17 +1178,18 @@ return underlying exceptions.
11781178
.. code-block:: python
11791179
11801180
from influxdb_client import InfluxDBClient
1181+
from influxdb_client.client.exceptions import InfluxDBError
11811182
11821183
11831184
class BatchingCallback(object):
11841185
11851186
def success(self, conf: (str, str, str), data: str):
11861187
print(f"Written batch: {conf}, data: {data}")
11871188
1188-
def error(self, conf: (str, str, str), data: str, exception: Exception):
1189+
def error(self, conf: (str, str, str), data: str, exception: InfluxDBError):
11891190
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")
11901191
1191-
def retry(self, conf: (str, str, str), data: str, exception: Exception):
1192+
def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError):
11921193
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")
11931194
11941195

examples/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- [ingest_large_dataframe.py](ingest_large_dataframe.py) - How to ingest large DataFrame
88
- [iot_sensor.py](iot_sensor.py) - How to write sensor data every minute by [RxPY](https://rxpy.readthedocs.io/en/latest/)
99
- [import_data_set_sync_batching.py](import_data_set_sync_batching.py) - How to use [RxPY](https://rxpy.readthedocs.io/en/latest/) to prepare batches for synchronous write into InfluxDB
10-
- [write_api_callbacks.py](write_api_callbacks.py) - How to use `WriteApi`'s callbacks to notify about state of background batches
10+
- [write_api_callbacks.py](write_api_callbacks.py) - How to handle batch events
1111

1212
## Queries
1313
- [query.py](query.py) - How to query data into `FluxTable`s, `Stream` and `CSV`

examples/write_api_callbacks.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
from influxdb_client import InfluxDBClient, Point
6+
from influxdb_client.client.exceptions import InfluxDBError
67

78
"""
89
Configuration
@@ -25,11 +26,11 @@ def success(self, conf: (str, str, str), data: str):
2526
"""Successfully writen batch."""
2627
print(f"Written batch: {conf}, data: {data}")
2728

28-
def error(self, conf: (str, str, str), data: str, exception: Exception):
29+
def error(self, conf: (str, str, str), data: str, exception: InfluxDBError):
2930
"""Unsuccessfully writen batch."""
3031
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")
3132

32-
def retry(self, conf: (str, str, str), data: str, exception: Exception):
33+
def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError):
3334
"""Retryable error."""
3435
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")
3536

influxdb_client/client/influxdb_client.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,18 @@ def write_api(self, write_options=WriteOptions(), point_settings=PointSettings()
278278
.. code-block:: python
279279
280280
from influxdb_client import InfluxDBClient
281+
from influxdb_client.client.exceptions import InfluxDBError
281282
282283
283284
class BatchingCallback(object):
284285
285286
def success(self, conf: (str, str, str), data: str):
286287
print(f"Written batch: {conf}, data: {data}")
287288
288-
def error(self, conf: (str, str, str), data: str, exception: Exception):
289+
def error(self, conf: (str, str, str), data: str, exception: InfluxDBError):
289290
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")
290291
291-
def retry(self, conf: (str, str, str), data: str, exception: Exception):
292+
def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError):
292293
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")
293294
294295

tests/test_WriteApiBatching.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def __init__(self):
563563
self.data = None
564564
self.error = None
565565

566-
def __call__(self, conf: (str, str, str), data: str, error: ApiException):
566+
def __call__(self, conf: (str, str, str), data: str, error: InfluxDBError):
567567
self.conf = conf
568568
self.data = data
569569
self.error = error
@@ -590,8 +590,8 @@ def __call__(self, conf: (str, str, str), data: str, error: ApiException):
590590
self.assertEqual("my-org", callback.conf[1])
591591
self.assertEqual("ns", callback.conf[2])
592592
self.assertIsNotNone(callback.error)
593-
self.assertEqual(ApiException, type(callback.error))
594-
self.assertEqual(400, callback.error.status)
593+
self.assertIsInstance(callback.error, InfluxDBError)
594+
self.assertEqual(400, callback.error.response.status)
595595

596596
def test_retry_callback(self):
597597
httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=204)
@@ -634,7 +634,7 @@ def __call__(self, conf: (str, str, str), data: str, error: InfluxDBError):
634634
self.assertEqual("my-org", callback.conf[1])
635635
self.assertEqual("ns", callback.conf[2])
636636
self.assertIsNotNone(callback.error)
637-
self.assertEqual(InfluxDBError, type(callback.error))
637+
self.assertIsInstance(callback.error, InfluxDBError)
638638
self.assertEqual(429, callback.error.response.status)
639639

640640

0 commit comments

Comments
 (0)