-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy patherrors.py
More file actions
32 lines (24 loc) · 890 Bytes
/
errors.py
File metadata and controls
32 lines (24 loc) · 890 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
import json
from http import HTTPStatus
class InvalidLogResponseException(Exception):
pass
class InvalidStatusCode(Exception):
def __init__(self, status_code: HTTPStatus, body, request_id=None):
self.status_code = status_code
self.body = body
self.request_id = request_id
def __str__(self):
error_message = self.status_code.name
if isinstance(self.body, str):
error_message += f" = {self.body}"
else:
error_message += f" = {json.dumps(self.body)}"
if self.request_id:
error_message += f" - vcap-request-id = {self.request_id}"
return error_message
class InvalidEntity(Exception):
def __init__(self, **kwargs):
super().__init__()
self.raw_entity = dict(**kwargs)
def __str__(self):
return "InvalidEntity: %s" % json.dumps(self.raw_entity)