Skip to content

Conversation

Adriel007
Copy link

  • Using isinstance:

    • The use of isinstance improves readability and is the recommended way to check types.
  • Exception Handling:

    • Added checks and exception handling to deal with network failures and other possible exceptions during the request.
  • Timeout:

    • Added a timeout option to prevent the code from hanging indefinitely waiting for a response.
  • Code Readability Improvement:

    • General improvements in code readability, making it clearer and easier to understand.

- **Using `isinstance`**:
  - The use of `isinstance` improves readability and is the recommended way to check types.

- **Exception Handling**:
  - Added checks and exception handling to deal with network failures and other possible exceptions during the request.

- **Timeout**:
  - Added a timeout option to prevent the code from hanging indefinitely waiting for a response.

- **Code Readability Improvement**:
  - General improvements in code readability, making it clearer and easier to understand.
)
response.raise_for_status()
except requests.exceptions.RequestException as e:
raise SystemExit(f"Request failed: {e}")
Copy link

Choose a reason for hiding this comment

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

Raising SystemExit in an RPC client tends to be counterproductive: Better to inform the caller of the actual error (which, in this case, would mean keeping the original exception, unless you can extract more precise information, such as the old client's check for an error key).

Copy link

Choose a reason for hiding this comment

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

To clarify: I think raising ValueError here rather than asserting is a good change, but would suggest not catching the RequestException.


if result_field:
res = res[result_field]
return Response(res.get(result_field, {}))
Copy link

Choose a reason for hiding this comment

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

This looks like a subtle, and incorrect, behavior change: The previous code would raise a KeyError if the response doesn't contain result_field, whereas the new code returns an empty response, thereby silently ignoring malformed responses. I would suggest reverting this change.

@Adriel007 Adriel007 closed this Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants