iro/error.py
branchdevel
changeset 267 ef2df3f23cb1
parent 225 70dafbaf21af
child 294 0e75bd39767d
equal deleted inserted replaced
266:a0adcb788fec 267:ef2df3f23cb1
     1 # -*- coding: utf-8 -*-
     1 # -*- coding: utf-8 -*-
     2 class InterfaceException(Exception):
     2 class InterfaceException(Exception):
     3     def __init__(self, code=999, msg="Unbekannter Fehler."):
     3     """Exception, that should be reported to external client
       
     4     
       
     5     999 -- unknown error
       
     6     """
       
     7     def __init__(self, code=999, msg="Unknown error."):
       
     8         """
       
     9         :param integer code: the error code
       
    10         :param string msg: the error message
       
    11         """
     4         self.code=code
    12         self.code=code
     5         self.msg=msg
    13         self.msg=msg
     6 
    14 
     7     def dict(self):
    15     def dict(self):
       
    16         """dict representation of the error"""
     8         return {"code":self.code,
    17         return {"code":self.code,
     9                 "msg":self.msg,
    18                 "msg":self.msg,
    10                 }
    19                 }
       
    20 
    11     def __str__(self):
    21     def __str__(self):
    12         return "%i: %s"%(self.code,self.msg)
    22         return "%i: %s"%(self.code,self.msg)
    13 
    23 
    14 class UserNotFound(InterfaceException):
    24 class UserNotFound(InterfaceException):
       
    25     """ 901 -- apikey is unknown -- user not found""" 
    15     def __init__(self):
    26     def __init__(self):
    16         InterfaceException.__init__(self, 901, "API-Key is unknown.")
    27         InterfaceException.__init__(self, 901, "Apikey is unknown.")
    17 
    28 
    18 class JobNotFound(InterfaceException):
    29 class JobNotFound(InterfaceException):
       
    30     """902 -- jobid is unknown"""
    19     def __init__(self):
    31     def __init__(self):
    20         InterfaceException.__init__(self, 902, "Jobid is unknown.")
    32         InterfaceException.__init__(self, 902, "Jobid is unknown.")
    21 
    33 
    22 class ExternalException(InterfaceException):
    34 class ExternalException(InterfaceException):
       
    35     """950 -- error in external api"""
    23     def __init__(self):
    36     def __init__(self):
    24         InterfaceException.__init__(self, 950, "Error in external API.")
    37         InterfaceException.__init__(self, 950, "Error in external API.")
    25 
    38 
    26 class ValidateException(Exception):
    39 class ValidateException(Exception):
       
    40     """700 -- validation failed."""
    27     def __init__(self, code=700, field=None, msg=None):
    41     def __init__(self, code=700, field=None, msg=None):
       
    42         """
       
    43         :param integer code: the error code
       
    44         :param string field: the field, that is not valid 
       
    45         :param string msg: the error message
       
    46         """
    28         self.code=code
    47         self.code=code
    29         self.field=field
    48         self.field=field
    30         self.msg = msg
    49         self.msg = msg
    31         if not msg:
    50         if not msg:
    32             self.msg='Validation failed.'
    51             self.msg='Validation failed.'
    33         if field and not msg:
    52         if field and not msg:
    34             self.msg="Validation of '%s' failed."%field
    53             self.msg="Validation of '%s' failed."%field
    35 
    54 
    36     def dict(self):
    55     def dict(self):
       
    56         """dict representation of the error"""
    37         return {"code":self.code,
    57         return {"code":self.code,
    38                 "msg":self.msg,
    58                 "msg":self.msg,
       
    59                 "field":self.field,
    39                 }
    60                 }
    40     def __str__(self):
    61     def __str__(self):
    41         return "%i: %s"%(self.code,self.msg)
    62         return "%i: %s"%(self.code,self.msg)
    42 
    63 
    43 class InvalidTel(ValidateException):
    64 class InvalidTel(ValidateException):
       
    65     """701 -- invalid telnumber"""
    44     def __init__(self, number,field=None):
    66     def __init__(self, number,field=None):
    45         self.number = number
    67         self.number = number
    46         msg = "No valid telnumber: '%s'"%(number)
    68         msg = "No valid telnumber: '%s'"%(number)
    47         ValidateException.__init__(self, 701, field, msg)
    69         ValidateException.__init__(self, 701, field, msg)
    48     
    70     
    49 class InvalidMail(ValidateException):
    71 class InvalidMail(ValidateException):
       
    72     """702 -- invalid mailaddress"""
    50     def __init__(self, number,field=None):
    73     def __init__(self, number,field=None):
    51         self.number = number
    74         self.number = number
    52         msg = "No valid email: '%s'"%(number)
    75         msg = "No valid email: '%s'"%(number)
    53         ValidateException.__init__(self, 702, field, msg)
    76         ValidateException.__init__(self, 702, field, msg)
    54 
    77 
    55 class OfferException(Exception):
    78 class OfferException(Exception):
       
    79     """an Exception in Offer handling"""
    56     def __init__(self, name):
    80     def __init__(self, name):
    57         self.name = name
    81         self.name = name
    58 
    82 
    59 class NoRoute(OfferException):
    83 class NoRoute(OfferException):
       
    84     """no valid route found"""
    60     def __str__(self):
    85     def __str__(self):
    61         return "Not a valid route: %s"%self.name
    86         return "Not a valid route: %s"%self.name
    62 
    87 
    63 class NoProvider(OfferException):
    88 class NoProvider(OfferException):
       
    89     """no provider found"""
    64     def __str__(self):
    90     def __str__(self):
    65         return "Not a valid provider: %s"%self.name
    91         return "Not a valid provider: %s"%self.name
    66 
    92 
    67 class NoTyp(OfferException):
    93 class NoTyp(OfferException):
       
    94     """no typ found."""
    68     def __str__(self):
    95     def __str__(self):
    69         return "Not a valid Typ: %s"%self.name
    96         return "Not a valid Typ: %s"%self.name
    70 
    97 
    71 class RejectRecipient(Exception):
    98 class RejectRecipient(Exception):
       
    99     """can't handle the recipient in a route"""
    72     def __init__(self,recipient, status=None):
   100     def __init__(self,recipient, status=None):
    73         self.recipient = recipient
   101         self.recipient = recipient
    74         self.status = status
   102         self.status = status
    75 
   103 
    76     def __str__(self):
   104     def __str__(self):
    77         return "Reject recipient(%s): %s"%(str(self.recipient),str(self.status))
   105         return "Reject recipient(%s): %s"%(str(self.recipient),str(self.status))
    78 
   106 
    79 class ConfigException(Exception):
   107 class ConfigException(Exception):
       
   108     """Exception while loading configuration."""
    80     def __init__(self,section, name):
   109     def __init__(self,section, name):
    81         self.section = section
   110         self.section = section
    82         self.name = name
   111         self.name = name
    83 
   112 
    84 class UnknownOption(ConfigException):
   113 class UnknownOption(ConfigException):
       
   114     """Option is unknown"""
    85     def __str__(self):
   115     def __str__(self):
    86         return "Unknown option '%s' in section '%s'."%(self.name, self.section)
   116         return "Unknown option '%s' in section '%s'."%(self.name, self.section)
    87 
   117 
    88 class NeededOption(ConfigException):
   118 class NeededOption(ConfigException):
       
   119     """Option is missing, but needed."""
    89     def __str__(self):
   120     def __str__(self):
    90         return "Option '%s' in section '%s' is missing."%(self.name, self.section)
   121         return "Option '%s' in section '%s' is missing."%(self.name, self.section)
    91 
   122 
    92 class NoRouteForTask(Exception):
   123 class NoRouteForTask(Exception):
       
   124     """Can't send message to recipient with given offers"""
    93     pass
   125     pass