[cdp][java] Allow filters to recover from failed requests in NetworkInterceptor
User description
Thanks for contributing to Selenium! A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines. Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
This change introduces a new exception, which is thrown through the user's filter chain when the browser fails to get a response for a request and a NetworkInterceptor is in use.
This gives the filter an opportunity to catch the exception and return a custom HTTP response.
Motivation and Context
Allow the user to intercept failed requests. See #13774 for more details.
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist
- [x] I have read the contributing document.
- [?] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
I'm not sure if this requires a documentation change but I think it would probably help and I'm happy to do that, if others agree.
Type
Enhancement, Tests
Description
- Introduced
RequestFailedExceptionto manage scenarios where the browser fails to send a HTTP request, allowing for custom error handling. - Enhanced the
Network.javato throw and handleRequestFailedExceptionappropriately, giving users the ability to respond with custom HTTP responses or to let the browser handle the error. - Added unit tests to validate the new exception handling mechanism, ensuring that both caught and uncaught exceptions behave as expected.
Changes walkthrough
| Relevant files | |||||
|---|---|---|---|---|---|
| Enhancement |
| ||||
| Tests |
|
✨ PR-Agent usage: Comment
/helpon the PR to get a list of all available PR-Agent tools and their descriptions
The changes LGTM. Can you help open it up for review? Please also sign the CLA @joebandenburg. Thank you for your contribution.
PR Description updated to latest commit (https://github.com/SeleniumHQ/selenium/commit/1a6c55caf0b4ddd346fef0510c9ee8977bbbca17)
- [ ] Copy walkthrough table to "Files Changed" Tab
PR Review
| ⏱️ Estimated effort to review [1-5] |
3, because the PR introduces a new exception handling mechanism within the network interceptor logic, which involves understanding the flow of HTTP requests and responses, exception propagation, and the integration with existing components. The changes are moderate in size but high in complexity due to the interaction between multiple components and the need to handle asynchronous operations correctly. |
| 🧪 Relevant tests |
Yes |
| 🔍 Possible issues |
Possible Bug: The handling of |
|
Error Handling: The new exception handling introduces changes in the flow of network operations, which could lead to unintended behaviors if the exception is not caught or managed correctly in user-defined filters. | |
| 🔒 Security concerns |
No |
✨ Review tool usage guide:
Overview:
The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.
The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
- When commenting, to edit configurations related to the review tool (
pr_reviewersection), use the following template:
/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
- With a configuration file, use the following template:
[pr_reviewer]
some_config1=...
some_config2=...
See the review usage page for a comprehensive guide on using this tool.
PR Code Suggestions
| Category | Suggestions | |||||
| Enhancement |
Add logging when a
| |||||
Log
| ||||||
Log unhandled
| ||||||
Add a general exception handler to catch and log unexpected exceptions.To ensure that all exceptions are properly handled, consider adding a general catch block java/src/org/openqa/selenium/devtools/idealized/Network.java [278-280]
| ||||||
| Best practice |
Safely cast exceptions to their specific types before rethrowing to avoid ClassCastException.To improve the robustness of the error handling, consider verifying the type of the java/src/org/openqa/selenium/devtools/idealized/Network.java [252-255]
|
✨ Improve tool usage guide:
Overview:
The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
- When commenting, to edit configurations related to the improve tool (
pr_code_suggestionssection), use the following template:
/improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
- With a configuration file, use the following template:
[pr_code_suggestions]
some_config1=...
some_config2=...
See the improve usage page for a comprehensive guide on using this tool.
I'm not sure whether this constitutes a breaking API change. Existing filters may already catch WebDriverException, RuntimeException or Exception. If that's the case, the behaviour reverts to how it was prior to #13836 landing. So looking at the combination of this change and #13836, I don't think it's a breaking change.