iro/error.py
branchdevel
changeset 267 ef2df3f23cb1
parent 225 70dafbaf21af
child 294 0e75bd39767d
--- a/iro/error.py	Fri Mar 30 02:25:20 2012 +0200
+++ b/iro/error.py	Fri Mar 30 11:23:22 2012 +0200
@@ -1,30 +1,49 @@
 # -*- coding: utf-8 -*-
 class InterfaceException(Exception):
-    def __init__(self, code=999, msg="Unbekannter Fehler."):
+    """Exception, that should be reported to external client
+    
+    999 -- unknown error
+    """
+    def __init__(self, code=999, msg="Unknown error."):
+        """
+        :param integer code: the error code
+        :param string msg: the error message
+        """
         self.code=code
         self.msg=msg
 
     def dict(self):
+        """dict representation of the error"""
         return {"code":self.code,
                 "msg":self.msg,
                 }
+
     def __str__(self):
         return "%i: %s"%(self.code,self.msg)
 
 class UserNotFound(InterfaceException):
+    """ 901 -- apikey is unknown -- user not found""" 
     def __init__(self):
-        InterfaceException.__init__(self, 901, "API-Key is unknown.")
+        InterfaceException.__init__(self, 901, "Apikey is unknown.")
 
 class JobNotFound(InterfaceException):
+    """902 -- jobid is unknown"""
     def __init__(self):
         InterfaceException.__init__(self, 902, "Jobid is unknown.")
 
 class ExternalException(InterfaceException):
+    """950 -- error in external api"""
     def __init__(self):
         InterfaceException.__init__(self, 950, "Error in external API.")
 
 class ValidateException(Exception):
+    """700 -- validation failed."""
     def __init__(self, code=700, field=None, msg=None):
+        """
+        :param integer code: the error code
+        :param string field: the field, that is not valid 
+        :param string msg: the error message
+        """
         self.code=code
         self.field=field
         self.msg = msg
@@ -34,41 +53,50 @@
             self.msg="Validation of '%s' failed."%field
 
     def dict(self):
+        """dict representation of the error"""
         return {"code":self.code,
                 "msg":self.msg,
+                "field":self.field,
                 }
     def __str__(self):
         return "%i: %s"%(self.code,self.msg)
 
 class InvalidTel(ValidateException):
+    """701 -- invalid telnumber"""
     def __init__(self, number,field=None):
         self.number = number
         msg = "No valid telnumber: '%s'"%(number)
         ValidateException.__init__(self, 701, field, msg)
     
 class InvalidMail(ValidateException):
+    """702 -- invalid mailaddress"""
     def __init__(self, number,field=None):
         self.number = number
         msg = "No valid email: '%s'"%(number)
         ValidateException.__init__(self, 702, field, msg)
 
 class OfferException(Exception):
+    """an Exception in Offer handling"""
     def __init__(self, name):
         self.name = name
 
 class NoRoute(OfferException):
+    """no valid route found"""
     def __str__(self):
         return "Not a valid route: %s"%self.name
 
 class NoProvider(OfferException):
+    """no provider found"""
     def __str__(self):
         return "Not a valid provider: %s"%self.name
 
 class NoTyp(OfferException):
+    """no typ found."""
     def __str__(self):
         return "Not a valid Typ: %s"%self.name
 
 class RejectRecipient(Exception):
+    """can't handle the recipient in a route"""
     def __init__(self,recipient, status=None):
         self.recipient = recipient
         self.status = status
@@ -77,17 +105,21 @@
         return "Reject recipient(%s): %s"%(str(self.recipient),str(self.status))
 
 class ConfigException(Exception):
+    """Exception while loading configuration."""
     def __init__(self,section, name):
         self.section = section
         self.name = name
 
 class UnknownOption(ConfigException):
+    """Option is unknown"""
     def __str__(self):
         return "Unknown option '%s' in section '%s'."%(self.name, self.section)
 
 class NeededOption(ConfigException):
+    """Option is missing, but needed."""
     def __str__(self):
         return "Option '%s' in section '%s' is missing."%(self.name, self.section)
 
 class NoRouteForTask(Exception):
+    """Can't send message to recipient with given offers"""
     pass