blob: feafd7668badaebab885f4e4660d519cc90301a6 [file] [log] [blame]
Marek Szwalkiewiczbe4c4642020-01-30 13:49:18 +00001"""Copyright 2019 Deutsche Telekom.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14"""
15
16
17class ArtifactManagerError(Exception):
18 """Base Artifact Manager exception class."""
19
20 status_code: int = 0
21 message: str = "Error"
22
23 def __init__(self, message: str = None) -> None:
24 """Initialize exception with optional message."""
25 if message:
26 self.message: str = message
27
28 @property
29 def status_code(self) -> int:
30 """Artifact Manager error class status code.
31
32 Base class has no and shouldn't have any status code.
33 """
34 if self.status_code == 0:
35 raise NotImplementedError
36 return self.status_code
37
38
39class InvalidRequestError(ArtifactManagerError):
40 """Raised when request has invalid or incomplete data."""
41
42 status_code: int = 500
43 message: str = "Invalid request"
44
45
46class ArtifactNotFoundError(ArtifactManagerError):
47 """Raised when requested artifact doesn't exist in system."""
48
49 status_code: int = 500
50 message: str = "Artifact not found"
51
52
53class ArtifactIOError(ArtifactManagerError):
54 """Raised on input/output error."""
55
56 status_code: int = 500
57 message: str = "Artifact is corrupted"
58
59
60class ArtifactOverwriteError(ArtifactManagerError):
61 """Raised when we cannot remove old artifact to save new."""
62
63 status_code: int = 500
64 message: str = "Artifact already exists and cannot be overwritten"