-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy path__init__.py
More file actions
102 lines (76 loc) · 2.95 KB
/
__init__.py
File metadata and controls
102 lines (76 loc) · 2.95 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
from typing import Optional
from openeo import BaseOpenEoException
# TODO: get from config file
DEFAULT_DOWNLOAD_CHUNK_SIZE = 10_000_000 # 10MB
DEFAULT_DOWNLOAD_RANGE_SIZE = 500_000_000 # 500MB
DEFAULT_JOB_STATUS_POLL_INTERVAL_MAX = 60
DEFAULT_JOB_STATUS_POLL_CONNECTION_RETRY_INTERVAL = 30
DEFAULT_JOB_STATUS_POLL_SOFT_ERROR_MAX = 10
CONFORMANCE_JWT_BEARER = "https://api.openeo.org/*/authentication/jwt"
class OpenEoClientException(BaseOpenEoException):
"""Base class for OpenEO client exceptions"""
pass
class CapabilitiesException(OpenEoClientException):
"""Back-end does not support certain openEO feature or endpoint."""
class JobFailedException(OpenEoClientException):
"""A synchronous batch job failed. This exception references its corresponding job so the client can e.g.
retrieve its logs.
"""
def __init__(self, message, job):
super().__init__(message)
self.job = job
class OperatorException(OpenEoClientException):
"""Invalid (mathematical) operator usage."""
pass
class BandMathException(OperatorException):
"""Invalid "band math" usage."""
pass
class OpenEoRestError(OpenEoClientException):
pass
class OpenEoApiPlainError(OpenEoRestError):
"""
Base class for openEO API error responses, not necessarily following the openEO API specification
(e.g. not properly JSON encoded, missing required fields, ...)
:param message: the direct error message from the response
:param http_status_code: the HTTP status code of the response
:param error_message: the error message to show when the exception is rendered
(by default a combination of the HTTP status code and the message)
.. versionadded:: 0.25.0
"""
__slots__ = ("http_status_code", "message")
def __init__(
self,
message: str,
*,
http_status_code: Optional[int] = None,
error_message: Optional[str] = None,
):
super().__init__(error_message or f"[{http_status_code}] {message}")
self.http_status_code = http_status_code
self.message = message
class OpenEoApiError(OpenEoApiPlainError):
"""
Exception for API error responses following the openEO API specification
(https://api.openeo.org/#section/API-Principles/Error-Handling):
JSON-encoded body, some expected fields like "code" and "message", ...
"""
__slots__ = ("http_status_code", "code", "message", "id", "url")
def __init__(
self,
*,
http_status_code: int,
code: str,
message: str,
id: Optional[str] = None,
url: Optional[str] = None,
):
super().__init__(
message=message,
http_status_code=http_status_code,
error_message=f"[{http_status_code}] {code}: {message}" + (f" (ref: {id})" if id else ""),
)
self.http_status_code = http_status_code
self.code = code
self.message = message
self.id = id
self.url = url