iro/error.py
branchdevel
changeset 110 601fc908d9f1
parent 92 f479738b4879
child 116 48c70425bf6c
--- 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)
+
+