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

added error catching code #81

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion discovery/playwright_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _is_web3_call(request: str):
pass # Can be inferred as non-Web3 call
return False

async def _async_forward_rpc_node_reqs(route):
async def _async_forward_rpc_node_reqs_old(route):
request = route.request
data = json.loads(request.post_data)
response = requests.post(tenderly_fork_url, json=data, headers=request.headers)
Expand All @@ -132,6 +132,28 @@ async def _async_forward_rpc_node_reqs(route):
body=response.content
)

async def _async_forward_rpc_node_reqs(route):
request = route.request
data = json.loads(request.post_data)
response = requests.post(tenderly_fork_url, json=data, headers=request.headers)

# Check if status code is 400
if response.status_code == 400:
# Write the request data to a file with the current time in the filename
filename = f"error_{time.strftime('%Y%m%d_%H%M%S')}.txt"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is called for every Web3 request that is routed/forwarded, it seems like this logic would create a new error log file for every 400 that is encountered
Ideally, you would want to setup the error log file at the start of the session and re-use that to capture all the errors in a single file, similar to how it is being done for the existing log file
https://github.com/yieldprotocol/chatweb3-backend/blob/dev/discovery/playwright_browser.py#L208

with open(filename, 'w') as file:
file.write(json.dumps(data, indent=4))

# Do not forward the request
print(f"Error: failed to forward request. Data saved in {filename}")
await route.continue_()
else:
await route.fulfill(
status=response.status_code,
headers=dict(response.headers),
body=response.content
)

async def _intercept_rpc_node_reqs(route):
if route.request.post_data and _is_web3_call(route.request):
# print(f"Forwarding:{route.request.url}")
Expand Down