exceptions.py 2.07 KB
Newer Older
Michal Simon's avatar
Michal Simon committed
1
#   Copyright notice:
2
#   Copyright  Members of the EMI Collaboration, 2013.
3
#
Michal Simon's avatar
Michal Simon committed
4
#   See www.eu-emi.eu for details on the copyright holders
5
#
Michal Simon's avatar
Michal Simon committed
6
7
8
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
9
#
Michal Simon's avatar
Michal Simon committed
10
#       http://www.apache.org/licenses/LICENSE-2.0
11
#
Michal Simon's avatar
Michal Simon committed
12
13
14
15
16
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
ayllon's avatar
ayllon committed
17

ayllon's avatar
ayllon committed
18
19
class FTS3ClientException(Exception):
    pass
ayllon's avatar
ayllon committed
20
21
22


class BadEndpoint(FTS3ClientException):
23
24
    def __init__(self, reason):
        self.reason = reason
ayllon's avatar
ayllon committed
25

ayllon's avatar
ayllon committed
26
    def __str__(self):
27
        return "Bad endpoint: %s" % self.reason
ayllon's avatar
ayllon committed
28
29
30


class Unauthorized(FTS3ClientException):
31
32
33
    def __init__(self, reason):
        self.reason = reason

ayllon's avatar
ayllon committed
34
    def __str__(self):
35
36
37
38
        if self.reason:
            return "Unauthorized: %s" % self.reason
        else:
            return "Unauthorized"
ayllon's avatar
ayllon committed
39
40
41


class ClientError(FTS3ClientException):
ayllon's avatar
ayllon committed
42
43
    def __init__(self, reason):
        self.reason = reason
ayllon's avatar
ayllon committed
44

ayllon's avatar
ayllon committed
45
46
    def __str__(self):
        return "Client error: %s" % self.reason
ayllon's avatar
ayllon committed
47
48


49
50
51
52
53
54
55
56
57
58
class NeedDelegation(ClientError):
    def __str__(self):
        return "Need to delegate credentials"


class FailedDependency(ClientError):
    def __str__(self):
        return "Failed dependency"


ayllon's avatar
ayllon committed
59
class ServerError(FTS3ClientException):
ayllon's avatar
ayllon committed
60
61
62
63
64
    def __init__(self, reason):
        self.reason = reason

    def __str__(self):
        return "Server error: %s" % self.reason
ayllon's avatar
ayllon committed
65
66


67
68
69
70
71
class TryAgain(ServerError):
    def __str__(self):
        return "Try again: %s" % self.reason


ayllon's avatar
ayllon committed
72
class NotFound(FTS3ClientException):
73
    def __init__(self, resource, reason=None):
ayllon's avatar
ayllon committed
74
        self.resource = resource
75
        self.reason = reason
ayllon's avatar
ayllon committed
76
77

    def __str__(self):
78
79
80
81
        if self.reason:
            return self.reason
        else:
            return "Not found: %s" % self.resource