iro/error.py
author Sandro Knauß <knauss@netzguerilla.net>
Fri, 27 Jan 2012 21:14:18 +0100
branchdevel
changeset 116 48c70425bf6c
parent 110 601fc908d9f1
child 125 19b3f383c9ce
permissions -rw-r--r--
validateexception.msg right use

# -*- coding: utf-8 -*-
class InterfaceException(Exception):
    def __init__(self, code=999, msg="Unbekannter Fehler."):
        self.code=code
        self.msg=msg

    def dict(self):
        return {"code":self.code,
                "msg":self.msg,
                }
    def __str__(self):
        return "%i:%s"%(self.code,self.msg)

class UserNotFound(InterfaceException):
    def __init__(self):
        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):
    def __init__(self, code=700, field=None, msg=None):
        self.code=code
        self.field=field
        self.msg = msg
        if not msg:
            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)