Skip to content

Commit 27c281b

Browse files
committed
add the status code in the Request exception
Create a InfluxDBClientError class as Exception This will give allow something similar to an HTTPError, including code and message instead of just message. It will make it easier to parse the exception, for example when trying to create a database that already exists. This may be a breaking change for some if they already parse the message. FYI, messages and codes are defined in Influxdb as : func errorToStatusCode(err error) int { switch err.(type) { case AuthenticationError: return libhttp.StatusUnauthorized // HTTP 401 case AuthorizationError: return libhttp.StatusForbidden // HTTP 403 case DatabaseExistsError: return libhttp.StatusConflict // HTTP 409 default: return libhttp.StatusBadRequest // HTTP 400 } }
1 parent 5767c53 commit 27c281b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

influxdb/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import requests
88
session = requests.Session()
99

10+
class InfluxDBClientError(Exception):
11+
"Raised when an error occures in Influxdb Client"
12+
pass
1013

1114
class InfluxDBClient(object):
1215
"""
@@ -95,9 +98,12 @@ def request(self, url, method='GET', params=None, data=None,
9598

9699
if response.status_code == status_code:
97100
return response
101+
98102
else:
99-
raise Exception(
100-
"{0}: {1}".format(response.status_code, response.content))
103+
error = InfluxDBClientError()
104+
error.message = "{0}: {1}".format(response.status_code, response.content)
105+
error.code = response.status_code
106+
raise error
101107

102108
# Writing Data
103109
#

0 commit comments

Comments
 (0)