summaryrefslogblamecommitdiffstats
path: root/glucometerutils/exceptions.py
blob: 3e73048d65bd86f0eff6704074c71436a2ef8276 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                       




                                                        
                   



                                  


                       
 






                                                    



                                                               
                                                              





                                              
                                                              
# -*- coding: utf-8 -*-
"""Common exceptions for glucometerutils."""

__author__ = 'Diego Elio Pettenò'
__email__ = 'flameeyes@flameeyes.eu'
__copyright__ = 'Copyright © 2013, Diego Elio Pettenò'
__license__ = 'MIT'

class Error(Exception):
  """Base class for the errors."""

  def __str__(self):
    return self.message


class ConnectionFailed(Error):
  """It was not possible to connect to the meter."""

  def __init__(self):
    self.message = 'Unable to connect to the meter.'


class InvalidResponse(Error):
  """The response received from the meter was not understood"""

  def __init__(self, response):
    self.message = 'Invalid response received:\n%s' % response


class InvalidGlucoseUnit(Error):
  """Unable to parse the given glucose unit"""

  def __init__(self, unit):
    self.message = 'Invalid glucose unit received:\n%s' % unit