errors.py 3.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
# Copyright (C) 2012, 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
#   1. Redistributions of source code must retain the above
#      copyright notice, this list of conditions and the following
#      disclaimer.
#
#   2. Redistributions in binary form must reproduce the above
#      copyright notice, this list of conditions and the following
#      disclaimer in the documentation and/or other materials
#      provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

34 35 36 37
"""
Astakos Client Exceptions
"""

38 39

class AstakosClientException(Exception):
40
    """Base AstakosClientException Class"""
41
    def __init__(self, message='', details='', status=500):
42
        self.message = message
43 44 45 46 47
        self.details = details
        if not hasattr(self, 'status'):
            self.status = status
        super(AstakosClientException,
              self).__init__(self.message, self.details, self.status)
48 49


50
class BadValue(AstakosClientException):
51
    """Re-define ValueError Exception under AstakosClientException"""
52 53 54 55 56
    def __init__(self, details):
        message = "ValueError"
        super(BadValue, self).__init__(message, details)


57
class InvalidResponse(AstakosClientException):
58
    """Return simplejson parse Exception as AstakosClient one"""
59 60 61 62
    def __init__(self, message, details):
        super(InvalidResponse, self).__init__(message, details)


63
class BadRequest(AstakosClientException):
64
    """BadRequest Exception"""
65
    status = 400
66 67 68


class Unauthorized(AstakosClientException):
69
    """Unauthorized Exception"""
70
    status = 401
71 72 73


class Forbidden(AstakosClientException):
74
    """Forbidden Exception"""
75
    status = 403
76 77 78


class NotFound(AstakosClientException):
79
    """NotFound Exception"""
80
    status = 404
81 82


83
class QuotaLimit(AstakosClientException):
84
    """QuotaLimit Exception"""
85 86 87
    status = 413


88
class NoUserName(AstakosClientException):
89
    """No display name for the given uuid"""
90 91
    def __init__(self, uuid):
        message = "No display name for the given uuid: %s" % uuid
92
        super(NoUserName, self).__init__(message)
93 94 95


class NoUUID(AstakosClientException):
96
    """No uuid for the given display name"""
97 98 99
    def __init__(self, display_name):
        message = "No uuid for the given display name: %s" % display_name
        super(NoUUID, self).__init__(message)
100 101 102 103 104 105 106 107 108 109 110 111 112


class NoEndpoints(AstakosClientException):
    """No endpoints found matching the criteria given"""
    def __init__(self, ep_name, ep_type, ep_region, ep_version_id):
        message = "No endpoints found matching" + \
                  (", name = %s" % ep_name) if ep_name is not None else "" + \
                  (", type = %s" % ep_type) if ep_type is not None else "" + \
                  (", region = %s" % ep_region) \
                  if ep_region is not None else "" + \
                  (", version_id = %s" % ep_version_id) \
                  if ep_version_id is not None else "."
        super(NoEndpoints, self).__init__(message)