errors.py 3.28 KB
Newer Older
Vangelis Koukis's avatar
Vangelis Koukis committed
1
# Copyright (C) 2010-2014 GRNET S.A.
2
#
Vangelis Koukis's avatar
Vangelis Koukis committed
3 4 5 6
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
7
#
Vangelis Koukis's avatar
Vangelis Koukis committed
8 9 10 11
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
12
#
Vangelis Koukis's avatar
Vangelis Koukis committed
13 14
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

16 17 18 19
"""
Astakos Client Exceptions
"""

20 21

class AstakosClientException(Exception):
22
    """Base AstakosClientException Class"""
23 24
    def __init__(self, message='', details='', status=500,
                 response=None, errobject=None):
25
        self.message = message
26
        self.details = details
27
        self.errobject = errobject
28
        self.response = response
29 30 31 32
        if not hasattr(self, 'status'):
            self.status = status
        super(AstakosClientException,
              self).__init__(self.message, self.details, self.status)
33 34


35 36 37 38 39 40 41
class ConnectionError(AstakosClientException):
    """Connection failed"""
    def __init__(self, errobject):
        super(ConnectionError, self).__init__(
            message=str(errobject), errobject=errobject)


42
class BadValue(AstakosClientException):
43
    """Re-define ValueError Exception under AstakosClientException"""
44 45 46 47 48
    def __init__(self, details):
        message = "ValueError"
        super(BadValue, self).__init__(message, details)


49
class InvalidResponse(AstakosClientException):
50
    """Return simplejson parse Exception as AstakosClient one"""
51 52


53
class BadRequest(AstakosClientException):
54
    """BadRequest Exception"""
55
    status = 400
56 57 58


class Unauthorized(AstakosClientException):
59
    """Unauthorized Exception"""
60
    status = 401
61 62 63


class Forbidden(AstakosClientException):
64
    """Forbidden Exception"""
65
    status = 403
66 67 68


class NotFound(AstakosClientException):
69
    """NotFound Exception"""
70
    status = 404
71 72


73
class QuotaLimit(AstakosClientException):
74
    """QuotaLimit Exception"""
75 76 77
    status = 413


78
class NoUserName(AstakosClientException):
79
    """No display name for the given uuid"""
80 81
    def __init__(self, uuid):
        message = "No display name for the given uuid: %s" % uuid
82
        super(NoUserName, self).__init__(message)
83 84 85


class NoUUID(AstakosClientException):
86
    """No uuid for the given display name"""
87 88 89
    def __init__(self, display_name):
        message = "No uuid for the given display name: %s" % display_name
        super(NoUUID, self).__init__(message)
90 91 92 93 94 95 96 97 98 99 100 101 102


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)