forked from blackducksoftware/hub-rest-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptions.py
More file actions
49 lines (36 loc) · 1004 Bytes
/
Exceptions.py
File metadata and controls
49 lines (36 loc) · 1004 Bytes
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
'''
Created on Dec 22, 2020
@author: ar-calder
'''
import logging
from json import JSONDecodeError
from .Utils import pfmt
logger = logging.getLogger(__name__)
class CreateFailedAlreadyExists(Exception):
pass
class CreateFailedUnknown(Exception):
pass
class InvalidVersionPhase(Exception):
pass
class UnknownVersion(Exception):
pass
class UnsupportedBDVersion(Exception):
# Some operations require specific versions of BD
pass
class EndpointNotFound(Exception):
pass
class UnacceptableContentType(Exception):
pass
def http_exception_handler(self, response, name):
error_codes = {
404 : EndpointNotFound,
406 : UnacceptableContentType
}
try:
content = pfmt(response.json())
except JSONDecodeError:
content = response.text
error = error_codes.get(response.status_code)
if error:
raise error(f"{name}: {content}")
raise NotImplementedError(f"No handler for status code: {response.status_code}")