Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
contego / home / tvault / .virtenv / lib / python2.7 / site-packages / contego / exception.py
Size: Mime:
# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright (c) 2015 TrilioData, Inc.
# All Rights Reserved.

"""Contego base exception handling.

"""

try:
    from oslo_log import log as logging
except ImportError:
    from nova.openstack.common import log as logging


LOG = logging.getLogger(__name__)


class ContegoException(Exception):
    """Base Contego Exception

    To correctly use this class, inherit from it and define
    a 'message' property. That message will get printf'd
    with the keyword arguments provided to the constructor.

    """
    message = ("Error: %(reason)s")
    code = 500
    headers = {}
    safe = False

    def __init__(self, message=None, **kwargs):
        self.kwargs = kwargs

        if 'code' not in self.kwargs:
            try:
                self.kwargs['code'] = self.code
            except AttributeError:
                pass

        if not message:
            try:
                message = self.message % kwargs

            except Exception:
                # kwargs doesn't match a variable in the message
                # log the issue and the kwargs
                LOG.exception('Exception in string format operation')
                for name, value in kwargs.iteritems():
                    LOG.error("%s: %s" % (name, value))

                # at least get the core message out if something happened
                message = self.message

        super(Exception, self).__init__(message)


class ErrorOccurred(ContegoException):
    message = "%(reason)s"


class TimeoutOccurred(ContegoException):
    message = "%(reason)s"


class InvalidNFSMountPoint(ContegoException):
    pass


class RetryException(ContegoException):
    pass


class NotFound(ContegoException):
    message = "Resource could not be found."
    code = 404

class FileNotFound(NotFound):
    message = "File %(file_path)s could not be found."