Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add additional data to ResponseInfo (box/box-codegen#439) #66

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "905c6a0", "specHash": "b2f7568", "version": "0.1.0" }
{ "engineHash": "df5b5de", "specHash": "b2f7568", "version": "0.1.0" }
22 changes: 17 additions & 5 deletions box_sdk_gen/box/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pprint
from typing import Optional
from typing import Any, Optional

from typing import Dict

Expand All @@ -10,14 +10,14 @@ def __init__(
message: str,
timestamp: str = None,
error: Optional[Exception] = None,
type: Optional[str] = None,
name: Optional[str] = None,
**kwargs,
):
super().__init__(message)
self.message = message
self.timestamp = timestamp
self.error = error
self.type = type
self.name = name

def __str__(self):
return ''.join(
Expand Down Expand Up @@ -69,17 +69,29 @@ def __init__(
headers: Dict[str, str],
body: Dict = None,
raw_body: Optional[str] = None,
code: Optional[str] = None,
context_info: Optional[Dict[str, Any]] = None,
request_id: Optional[str] = None,
help_url: Optional[str] = None,
):
self.status_code = status_code
self.headers = headers
self.body = body
self.raw_body = raw_body
self.code = code
self.context_info = context_info
self.request_id = request_id
self.help_url = help_url

def __str__(self):
return ''.join(
(
f'\n\tStatus code: {self.status_code}',
f'\n\tHeaders: \n{pprint.pformat(self.headers, indent=8)}',
f'\n\tCode: {self.code}',
f'\n\tContext Info: \n{pprint.pformat(self.context_info, indent=8)}',
f'\n\tRequest Id: {self.request_id}',
f'\n\tHelp Url: {self.help_url}',
''.join(
[
'\n\tBody: ',
Expand All @@ -100,11 +112,11 @@ def __init__(
message: str,
timestamp: str,
error: Optional[str] = None,
type: Optional[str] = None,
name: Optional[str] = None,
**kwargs,
):
super().__init__(
message=message, timestamp=timestamp, error=error, type=type, **kwargs
message=message, timestamp=timestamp, error=error, name=name, **kwargs
)
self.request_info = request_info
self.response_info = response_info
Expand Down
4 changes: 4 additions & 0 deletions box_sdk_gen/networking/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ def __raise_on_unsuccessful_request(request: APIRequest, response: APIResponse)
headers=dict(network_response.headers),
body=response_json,
raw_body=network_response.text,
code=response_json.get("code", None),
context_info=response_json.get("context_info", {}),
request_id=response_json.get("request_id", None),
help_url=response_json.get("help_url", None),
),
)

Expand Down
Loading