Debian Codegraph @

zaqarclient/transport/errors.py

raw
1 # Copyright (c) 2013 Red Hat, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16
17 """
18 Errors below must be used to translate transport specific
19 errors to Zaqar errors. For example, HTTP 404s should be
20 raised as `ResourceNotFound`
21 """
22
23 from zaqarclient import errors
24
25 __all__ = ['TransportError', 'ResourceNotFound', 'MalformedRequest',
26 'UnauthorizedError', 'ForbiddenError', 'ServiceUnavailableError',
27 'InternalServerError', 'ConflictError']
28
29
30 class TransportError(errors.ZaqarError):
31 """Base class for all transport errors."""
32
33 code = None
34
35 def __init__(self, title=None, description=None, text=None):
36 msg = 'Error response from Zaqar. Code: {}.'.format(self.code)
37 if title:
38 msg += ' Title: {}.'.format(title)
39 if description:
40 msg += ' Description: {}.'.format(description)
41 if text:
42 msg += ' Text: {}.'.format(text)
43 super().__init__(msg)
44
45
46 class ResourceNotFound(TransportError):
47 """Indicates that a resource is missing
48
49 This error maps to HTTP's 404
50 """
51
52 code = 404
53
54
55 class MalformedRequest(TransportError):
56 """Indicates that a request is malformed
57
58 This error maps to HTTP's 400
59 """
60
61 code = 400
62
63
64 class UnauthorizedError(TransportError):
65 """Indicates that a request was not authenticated
66
67 This error maps to HTTP's 401
68 """
69
70 code = 401
71
72
73 class ForbiddenError(TransportError):
74 """Indicates that a request is forbidden to access the particular resource
75
76 This error maps to HTTP's 403
77 """
78
79 code = 403
80
81
82 class InternalServerError(TransportError):
83 """Indicates that the server encountered an unexpected situation
84
85 This error maps to HTTP's 500
86 """
87
88 code = 500
89
90
91 class ServiceUnavailableError(TransportError):
92 """Indicates that the server was unable to service the request
93
94 This error maps to HTTP's 503
95 """
96
97 code = 503
98
99
100 class ConflictError(TransportError):
101 """Indicates that the server was unable to service the request
102
103 This error maps to HTTP's 409
104 """
105
106 code = 409