Source code for iro.error

# Copyright (c) 2012 netzguerilla.net <iro@netzguerilla.net>
# 
# This file is part of Iro.
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
# #Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# -*- coding: utf-8 -*-
[docs]class InterfaceException(Exception): """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
[docs] 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)
[docs]class UserNotFound(InterfaceException): """ 901 -- apikey is unknown -- user not found""" def __init__(self): InterfaceException.__init__(self, 901, "Apikey is unknown.")
[docs]class JobNotFound(InterfaceException): """902 -- jobid is unknown""" def __init__(self): InterfaceException.__init__(self, 902, "Jobid is unknown.")
[docs]class ExternalException(InterfaceException): """950 -- error in external api""" def __init__(self): InterfaceException.__init__(self, 950, "Error in external API.")
[docs]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 if not msg: self.msg='Validation failed.' if field and not msg: self.msg="Validation of '%s' failed."%field
[docs] 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)
[docs]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)
[docs]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)
[docs]class OfferException(Exception): """an Exception in Offer handling""" def __init__(self, name): self.name = name
[docs]class NoRoute(OfferException): """no valid route found""" def __str__(self): return "Not a valid route: %s"%self.name
[docs]class NoProvider(OfferException): """no provider found""" def __str__(self): return "Not a valid provider: %s"%self.name
[docs]class NoTyp(OfferException): """no typ found.""" def __str__(self): return "Not a valid Typ: %s"%self.name
[docs]class RejectRecipient(Exception): """can't handle the recipient in a route""" def __init__(self,recipient, status=None): self.recipient = recipient self.status = status def __str__(self): return "Reject recipient(%s): %s"%(str(self.recipient),str(self.status))
[docs]class ConfigException(Exception): """Exception while loading configuration.""" def __init__(self,section, name): self.section = section self.name = name
[docs]class UnknownOption(ConfigException): """Option is unknown""" def __str__(self): return "Unknown option '%s' in section '%s'."%(self.name, self.section)
[docs]class NeededOption(ConfigException): """Option is missing, but needed.""" def __str__(self): return "Option '%s' in section '%s' is missing."%(self.name, self.section)
[docs]class NoRouteForTask(Exception): """Can't send message to recipient with given offers""" pass