iro/error.py
branchdevel
changeset 110 601fc908d9f1
parent 92 f479738b4879
child 116 48c70425bf6c
equal deleted inserted replaced
109:935b5fcaf152 110:601fc908d9f1
     1 # -*- coding: utf-8 -*-
     1 # -*- coding: utf-8 -*-
     2 
       
     3 class InterfaceException(Exception):
     2 class InterfaceException(Exception):
     4     def __init__(self, code=999, msg="Unbekannter Fehler."):
     3     def __init__(self, code=999, msg="Unbekannter Fehler."):
     5         self.code=code
     4         self.code=code
     6         self.msg=msg
     5         self.msg=msg
     7 
     6 
    12     def __str__(self):
    11     def __str__(self):
    13         return "%i:%s"%(self.code,self.msg)
    12         return "%i:%s"%(self.code,self.msg)
    14 
    13 
    15 class UserNotFound(InterfaceException):
    14 class UserNotFound(InterfaceException):
    16     def __init__(self):
    15     def __init__(self):
    17         InterfaceException.__init__(self, 901, "Der API-Key ist ungültig.")
    16         InterfaceException.__init__(self, 901, u"Der API-Key ist ungültig.")
    18 
    17 
    19 class ExternalException(InterfaceException):
    18 class ExternalException(InterfaceException):
    20     def __init__(self):
    19     def __init__(self):
    21         InterfaceException.__init__(self, 950, "Fehler in externer API.")
    20         InterfaceException.__init__(self, 950, "Fehler in externer API.")
    22 
    21 
    23 class ValidateException(Exception):
    22 class ValidateException(Exception):
    24     pass
    23     def __init__(self, code=700, field=None, msg=None):
       
    24         self.code=code
       
    25         self.field=field
       
    26         self.msg='Validation failed.'
       
    27         if field and not msg:
       
    28             self.msg="Validation of '%s' failed."%field
       
    29 
       
    30     def dict(self):
       
    31         return {"code":self.code,
       
    32                 "msg":self.msg,
       
    33                 }
       
    34     def __str__(self):
       
    35         return "%i:%s"%(self.code,self.msg)
       
    36 
       
    37