Debian Codegraph @

influxdb/exceptions.py

raw
1 # -*- coding: utf-8 -*-
2 """Exception handler for InfluxDBClient."""
3
4 from __future__ import absolute_import
5 from __future__ import division
6 from __future__ import print_function
7 from __future__ import unicode_literals
8
9
10 class InfluxDBClientError(Exception):
11 """Raised when an error occurs in the request."""
12
13 def __init__(self, content, code=None):
14 """Initialize the InfluxDBClientError handler."""
15 if isinstance(content, type(b'')):
16 content = content.decode('UTF-8', 'replace')
17
18 if code is not None:
19 message = "%s: %s" % (code, content)
20 else:
21 message = content
22
23 super(InfluxDBClientError, self).__init__(
24 message
25 )
26 self.content = content
27 self.code = code
28
29
30 class InfluxDBServerError(Exception):
31 """Raised when a server error occurs."""
32
33 def __init__(self, content):
34 """Initialize the InfluxDBServerError handler."""
35 super(InfluxDBServerError, self).__init__(content)