diff -r 935b5fcaf152 -r 601fc908d9f1 iro/error.py --- a/iro/error.py Thu Jan 26 01:15:33 2012 +0100 +++ b/iro/error.py Thu Jan 26 01:18:47 2012 +0100 @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - class InterfaceException(Exception): def __init__(self, code=999, msg="Unbekannter Fehler."): self.code=code @@ -14,11 +13,25 @@ class UserNotFound(InterfaceException): def __init__(self): - InterfaceException.__init__(self, 901, "Der API-Key ist ungültig.") + InterfaceException.__init__(self, 901, u"Der API-Key ist ungültig.") class ExternalException(InterfaceException): def __init__(self): InterfaceException.__init__(self, 950, "Fehler in externer API.") class ValidateException(Exception): - pass + def __init__(self, code=700, field=None, msg=None): + self.code=code + self.field=field + self.msg='Validation failed.' + if field and not msg: + self.msg="Validation of '%s' failed."%field + + def dict(self): + return {"code":self.code, + "msg":self.msg, + } + def __str__(self): + return "%i:%s"%(self.code,self.msg) + +