Skip to content

Commit 239bce1

Browse files
committed
chore: use InfluxDBError instead ApiException
1 parent 922dc09 commit 239bce1

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
@@ -1185,17 +1185,18 @@ return underlying exceptions.
11851185
.. code-block:: python
11861186
11871187
from influxdb_client import InfluxDBClient
1188+
from influxdb_client.client.exceptions import InfluxDBError
11881189
11891190
11901191
class BatchingCallback(object):
11911192
11921193
def success(self, conf: (str, str, str), data: str):
11931194
print(f"Written batch: {conf}, data: {data}")
11941195
1195-
def error(self, conf: (str, str, str), data: str, exception: Exception):
1196+
def error(self, conf: (str, str, str), data: str, exception: InfluxDBError):
11961197
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")
11971198
1198-
def retry(self, conf: (str, str, str), data: str, exception: Exception):
1199+
def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError):
11991200
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")
12001201
12011202

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
- [write_structured_data.py](write_structured_data.py) - How to write structured data - [NamedTuple](https://docs.python.org/3/library/collections.html#collections.namedtuple), [Data Classes](https://docs.python.org/3/library/dataclasses.html) - (_requires Python v3.8+_)
1212

1313
## Queries

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
@@ -618,7 +618,7 @@ def __init__(self):
618618
self.data = None
619619
self.error = None
620620

621-
def __call__(self, conf: (str, str, str), data: str, error: ApiException):
621+
def __call__(self, conf: (str, str, str), data: str, error: InfluxDBError):
622622
self.conf = conf
623623
self.data = data
624624
self.error = error
@@ -645,8 +645,8 @@ def __call__(self, conf: (str, str, str), data: str, error: ApiException):
645645
self.assertEqual("my-org", callback.conf[1])
646646
self.assertEqual("ns", callback.conf[2])
647647
self.assertIsNotNone(callback.error)
648-
self.assertEqual(ApiException, type(callback.error))
649-
self.assertEqual(400, callback.error.status)
648+
self.assertIsInstance(callback.error, InfluxDBError)
649+
self.assertEqual(400, callback.error.response.status)
650650

651651
def test_retry_callback(self):
652652
httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=204)
@@ -689,7 +689,7 @@ def __call__(self, conf: (str, str, str), data: str, error: InfluxDBError):
689689
self.assertEqual("my-org", callback.conf[1])
690690
self.assertEqual("ns", callback.conf[2])
691691
self.assertIsNotNone(callback.error)
692-
self.assertEqual(InfluxDBError, type(callback.error))
692+
self.assertIsInstance(callback.error, InfluxDBError)
693693
self.assertEqual(429, callback.error.response.status)
694694

695695

0 commit comments

Comments
 (0)