11"""
2- CodeBox API Error Classes
2+ CodeBox API
3+ Error Classes
34"""
45
56
@@ -10,46 +11,19 @@ class CodeBoxError(Exception):
1011
1112 def __init__ (
1213 self ,
14+ http_status : int = 0 ,
15+ json_body : dict = {},
16+ headers : dict = {},
1317 ** kwargs ,
1418 ):
1519 super ().__init__ (** kwargs )
1620
17- if (http_body := kwargs .get ("http_body" )) and hasattr (http_body , "decode" ):
18- try :
19- http_body = http_body .decode ("utf-8" )
20- except BaseException :
21- http_body = (
22- "<Could not decode body as utf-8. "
23- "Please report to [email protected] >" 24- )
25-
26- self ._message = kwargs .get ("message" )
27- self .http_body = http_body
28- self .http_status = kwargs .get ("http_status" )
29- self .json_body = kwargs .get ("json_body" )
30- self .headers = kwargs .get ("headers" , {})
31- self .code = kwargs .get ("code" , None )
32- self .request_id = self .headers .get ("request-id" , None )
33- # self.error = self.construct_error_object() # TODO: implement
34- self .user_id = self .headers .get ("user_id" , None )
21+ self .http_status = http_status
22+ self .json_body = json_body
23+ self .headers = headers
3524
3625 def __str__ (self ):
37- msg = self ._message or "<empty message>"
38- if self .request_id is not None :
39- return f"Request { self .request_id } : { msg } "
40- return msg
26+ return f"{ self .http_status } : { self .json_body } "
4127
4228 def __repr__ (self ):
43- return f"<CodeBoxError[{ self .code } ] { self ._message } >"
44-
45- # def construct_error_object(self):
46- # if (
47- # self.json_body is None
48- # or "error" not in self.json_body
49- # or not isinstance(self.json_body["error"], dict)
50- # ):
51- # return None
52-
53- # return codebox.api_resources.error_object.ErrorObject.construct_from(
54- # self.json_body["error"]
55- # ) # TODO: implement
29+ return f"<CodeBoxError { self .http_status } : { self .json_body } >"
0 commit comments