aboutsummaryrefslogtreecommitdiffstats
path: root/src/onapsdk/exceptions.py
blob: a9977fdafdd0dd497f643fabb8fa3d66383ebfcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""ONAP Exception module."""
#   Copyright 2022 Orange, Deutsche Telekom AG
#
#   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
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   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.

from typing import Optional


class SDKException(Exception):
    """Generic exception for ONAP SDK."""


class RequestError(SDKException):
    """Request error occured."""


class ConnectionFailed(RequestError):
    """Unable to connect."""


class APIError(RequestError):
    """API error occured."""

    def __init__(self,
                 message: Optional[str] = None,
                 response_status_code: Optional[int] = None,
                 response_text: Optional[str] = None) -> None:
        """Init api error exception.

        Save message and optional response status code.

        Args:
            message (Optional[str]): Response error message. Defaults to None.
            response_status_code (Optional[int], optional): Response status code. Defaults to None.

        """
        if message:
            super().__init__(message)
        else:
            super().__init__()
        self._response_status_code: int = response_status_code if response_status_code else 0
        self._response_text: Optional[str] = response_text

    @property
    def response_status_code(self) -> int:
        """Response status code property.

        Returns:
            int: Response status code. If not set, returns 0

        """
        return self._response_status_code

    @response_status_code.setter
    def response_status_code(self, status_code: int) -> None:
        """Response status code property setter.

        Args:
            status_code (int): Response status code

        """
        self._response_status_code = status_code

    @property
    def response_text(self) -> Optional[str]:
        """Response status code property.

        Returns:
            int: Response status code. If not set, returns 0

        """
        return self._response_text

    @response_text.setter
    def response_text(self, response_text: str) -> None:
        """Response status code property setter.

        Args:
            status_code (int): Response status code

        """
        self._response_text = response_text


class InvalidResponse(RequestError):
    """Unable to decode response."""


class ResourceNotFound(APIError):
    """Requested resource does not exist."""


class RelationshipNotFound(ResourceNotFound):
    """Required relationship is missing."""


class StatusError(SDKException):
    """Invalid status."""


class ParameterError(SDKException):
    """Parameter does not satisfy requirements."""

class ModuleError(SDKException):
    """Unable to import module."""


class ValidationError(SDKException):
    """Data validation failed."""


class FileError(ValidationError):
    """Reading in a file failed."""


class SettingsError(SDKException):
    """Some settings are wrong."""


class NoGuiError(SDKException):
    """No GUI available for this component."""