forked from feldera/feldera
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.py
More file actions
55 lines (40 loc) · 1.66 KB
/
errors.py
File metadata and controls
55 lines (40 loc) · 1.66 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
from requests import Response
import json
class FelderaError(Exception):
"""
Generic class for Feldera error handling
"""
def __init__(self, message: str) -> None:
self.message = message
super().__init__(self.message)
def __str__(self) -> str:
return f"FelderaError. Error message: {self.message}"
class FelderaAPIError(FelderaError):
"""Error sent by Feldera API"""
def __init__(self, error: str, request: Response) -> None:
self.status_code = request.status_code
self.error = error
self.error_code = None
self.message = None
self.details = None
if request.text:
try:
json_data = json.loads(request.text)
self.message = json_data.get("message")
self.details = json_data.get("details")
self.error_code = json_data.get("error_code")
except:
self.message = request.text
def __str__(self) -> str:
if self.error_code:
return f"FelderaAPIError: {self.error}\n Error code: {self.error_code}\n Error message: {self.message}\n Details: {self.details}"
else:
return f"FelderaAPIError: {self.error}\n {self.message}"
class FelderaTimeoutError(FelderaError):
"""Error when Feldera operation takes longer than expected"""
def __str__(self) -> str:
return f"FelderaTimeoutError: {self.message}"
class FelderaCommunicationError(FelderaError):
"""Error when connection to Feldera"""
def __str__(self) -> str:
return f"FelderaCommunicationError: {self.message}"