-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathexceptions.py
More file actions
111 lines (82 loc) · 2.57 KB
/
Copy pathexceptions.py
File metadata and controls
111 lines (82 loc) · 2.57 KB
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
import json
from typing import TYPE_CHECKING
from ..utils import DataikuException
if TYPE_CHECKING:
import requests
class DataikuLaunchpadException(DataikuException):
"""
Exception launched by the Launchpad when a failure occurred
"""
class DataikuClientException(DataikuLaunchpadException):
"""
Exception launched by the client when a usage error occurred
"""
class DataikuResponseException(DataikuLaunchpadException):
"""
Base class for exceptions that wraps a response from the server
"""
def __init__(self, response: "requests.Response"):
self.response = response
try:
self._error = response.json()
except ValueError:
self._error = {"message": response.text}
super().__init__(self.message)
@property
def error(self) -> dict:
"""
The error as a dictionary
"""
return self._error
@property
def message(self) -> str:
"""
The error message
"""
return self._error.get("message", "Unknown error")
class DataikuTaskException(DataikuLaunchpadException):
"""
Exception launched when a task related failure occurred
"""
class DataikuMissingTaskException(DataikuTaskException):
"""
Exception launched when attempting to create a task object from a response lacking one
"""
class DataikuTaskTimeoutException(DataikuTaskException):
"""
Exception launched when timing out awaiting a task completion
"""
class DataikuBadRequestException(DataikuResponseException):
"""
Exception launched when the request is malformed
"""
@property
def error(self) -> dict:
"""
The error as a dictionary
"""
return self._error.get("errors", {}).get("json", self._error)
@property
def message(self) -> str:
"""
The error message
"""
return json.dumps(self.error)
class DataikuResourceDoesNotExistException(DataikuClientException):
"""
Exception launched when attempting to access an object that does not exist
"""
class DataikuResourceNotFoundException(
DataikuResponseException, DataikuResourceDoesNotExistException
):
"""
Exception launched when the resource is not found
"""
class DataikuUnauthorizedException(DataikuResponseException):
"""
Exception launched when trying to access a resource without proper authorization
"""
class DataikuForbiddenException(DataikuResponseException):
"""
Exception launched when trying to access a resource without proper scope
"""