exceptions.py 1012 B

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