Statistics
| Branch: | Tag: | Revision:

root / astakosclient / astakosclient / errors.py @ 2b40f200

History | View | Annotate | Download (3.1 kB)

1 f93cc364 Ilias Tsitsimpis
# Copyright (C) 2012, 2013 GRNET S.A. All rights reserved.
2 f93cc364 Ilias Tsitsimpis
#
3 f93cc364 Ilias Tsitsimpis
# Redistribution and use in source and binary forms, with or
4 f93cc364 Ilias Tsitsimpis
# without modification, are permitted provided that the following
5 f93cc364 Ilias Tsitsimpis
# conditions are met:
6 f93cc364 Ilias Tsitsimpis
#
7 f93cc364 Ilias Tsitsimpis
#   1. Redistributions of source code must retain the above
8 f93cc364 Ilias Tsitsimpis
#      copyright notice, this list of conditions and the following
9 f93cc364 Ilias Tsitsimpis
#      disclaimer.
10 f93cc364 Ilias Tsitsimpis
#
11 f93cc364 Ilias Tsitsimpis
#   2. Redistributions in binary form must reproduce the above
12 f93cc364 Ilias Tsitsimpis
#      copyright notice, this list of conditions and the following
13 f93cc364 Ilias Tsitsimpis
#      disclaimer in the documentation and/or other materials
14 f93cc364 Ilias Tsitsimpis
#      provided with the distribution.
15 f93cc364 Ilias Tsitsimpis
#
16 f93cc364 Ilias Tsitsimpis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 f93cc364 Ilias Tsitsimpis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 f93cc364 Ilias Tsitsimpis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 f93cc364 Ilias Tsitsimpis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 f93cc364 Ilias Tsitsimpis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 f93cc364 Ilias Tsitsimpis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 f93cc364 Ilias Tsitsimpis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 f93cc364 Ilias Tsitsimpis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 f93cc364 Ilias Tsitsimpis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 f93cc364 Ilias Tsitsimpis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 f93cc364 Ilias Tsitsimpis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 f93cc364 Ilias Tsitsimpis
# POSSIBILITY OF SUCH DAMAGE.
28 f93cc364 Ilias Tsitsimpis
#
29 f93cc364 Ilias Tsitsimpis
# The views and conclusions contained in the software and
30 f93cc364 Ilias Tsitsimpis
# documentation are those of the authors and should not be
31 f93cc364 Ilias Tsitsimpis
# interpreted as representing official policies, either expressed
32 f93cc364 Ilias Tsitsimpis
# or implied, of GRNET S.A.
33 f93cc364 Ilias Tsitsimpis
34 f93cc364 Ilias Tsitsimpis
35 f93cc364 Ilias Tsitsimpis
class AstakosClientException(Exception):
36 2b40f200 Christos Stavrakakis
    def __init__(self, message='', details='', status=500):
37 f93cc364 Ilias Tsitsimpis
        self.message = message
38 21190887 Ilias Tsitsimpis
        self.details = details
39 21190887 Ilias Tsitsimpis
        if not hasattr(self, 'status'):
40 21190887 Ilias Tsitsimpis
            self.status = status
41 21190887 Ilias Tsitsimpis
        super(AstakosClientException,
42 21190887 Ilias Tsitsimpis
              self).__init__(self.message, self.details, self.status)
43 f93cc364 Ilias Tsitsimpis
44 f93cc364 Ilias Tsitsimpis
45 83f9157b Ilias Tsitsimpis
class BadValue(AstakosClientException):
46 83f9157b Ilias Tsitsimpis
    def __init__(self, details):
47 83f9157b Ilias Tsitsimpis
        """Re-define ValueError Exception under AstakosClientException"""
48 83f9157b Ilias Tsitsimpis
        message = "ValueError"
49 83f9157b Ilias Tsitsimpis
        super(BadValue, self).__init__(message, details)
50 83f9157b Ilias Tsitsimpis
51 83f9157b Ilias Tsitsimpis
52 0a2a342c Ilias Tsitsimpis
class InvalidResponse(AstakosClientException):
53 0a2a342c Ilias Tsitsimpis
    def __init__(self, message, details):
54 0a2a342c Ilias Tsitsimpis
        """Return simplejson parse Exception as AstakosClient one"""
55 0a2a342c Ilias Tsitsimpis
        super(InvalidResponse, self).__init__(message, details)
56 0a2a342c Ilias Tsitsimpis
57 0a2a342c Ilias Tsitsimpis
58 f93cc364 Ilias Tsitsimpis
class BadRequest(AstakosClientException):
59 21190887 Ilias Tsitsimpis
    status = 400
60 f93cc364 Ilias Tsitsimpis
61 f93cc364 Ilias Tsitsimpis
62 f93cc364 Ilias Tsitsimpis
class Unauthorized(AstakosClientException):
63 21190887 Ilias Tsitsimpis
    status = 401
64 f93cc364 Ilias Tsitsimpis
65 f93cc364 Ilias Tsitsimpis
66 f93cc364 Ilias Tsitsimpis
class Forbidden(AstakosClientException):
67 21190887 Ilias Tsitsimpis
    status = 403
68 f93cc364 Ilias Tsitsimpis
69 f93cc364 Ilias Tsitsimpis
70 f93cc364 Ilias Tsitsimpis
class NotFound(AstakosClientException):
71 21190887 Ilias Tsitsimpis
    status = 404
72 2377e7c2 Ilias Tsitsimpis
73 2377e7c2 Ilias Tsitsimpis
74 fd420756 Ilias Tsitsimpis
class QuotaLimit(AstakosClientException):
75 fd420756 Ilias Tsitsimpis
    status = 413
76 fd420756 Ilias Tsitsimpis
77 fd420756 Ilias Tsitsimpis
78 794c94e6 Ilias Tsitsimpis
class NoUserName(AstakosClientException):
79 2377e7c2 Ilias Tsitsimpis
    def __init__(self, uuid):
80 2377e7c2 Ilias Tsitsimpis
        """No display name for the given uuid"""
81 2377e7c2 Ilias Tsitsimpis
        message = "No display name for the given uuid: %s" % uuid
82 794c94e6 Ilias Tsitsimpis
        super(NoUserName, self).__init__(message)
83 2377e7c2 Ilias Tsitsimpis
84 2377e7c2 Ilias Tsitsimpis
85 2377e7c2 Ilias Tsitsimpis
class NoUUID(AstakosClientException):
86 2377e7c2 Ilias Tsitsimpis
    def __init__(self, display_name):
87 2377e7c2 Ilias Tsitsimpis
        """No uuid for the given display name"""
88 2377e7c2 Ilias Tsitsimpis
        message = "No uuid for the given display name: %s" % display_name
89 2377e7c2 Ilias Tsitsimpis
        super(NoUUID, self).__init__(message)