Marek Szwalkiewicz | be4c464 | 2020-01-30 13:49:18 +0000 | [diff] [blame] | 1 | """Copyright 2019 Deutsche Telekom. |
| 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 implied. |
| 12 | See the License for the specific language governing permissions and |
| 13 | limitations under the License. |
| 14 | """ |
| 15 | |
| 16 | |
| 17 | class 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 | |
| 39 | class InvalidRequestError(ArtifactManagerError): |
| 40 | """Raised when request has invalid or incomplete data.""" |
| 41 | |
| 42 | status_code: int = 500 |
| 43 | message: str = "Invalid request" |
| 44 | |
| 45 | |
| 46 | class 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 | |
| 53 | class ArtifactIOError(ArtifactManagerError): |
| 54 | """Raised on input/output error.""" |
| 55 | |
| 56 | status_code: int = 500 |
| 57 | message: str = "Artifact is corrupted" |
| 58 | |
| 59 | |
| 60 | class 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" |