-
-
Notifications
You must be signed in to change notification settings - Fork 320
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
refactor(WebClient): add catch exception logic #5411
Conversation
Reviewer's Guide by SourceryThis pull request refactors the WebClient service to add exception handling and remove the Sequence diagram for GetClientInfo with exception handlingsequenceDiagram
participant WC as WebClientService
participant JSR as JSRuntime
participant JS as client.js
participant Server
participant DotNetObject
WC->>JSR: LoadModuleByName("client")
alt JSModule is loaded successfully
JSR-->>WC: JSModule
WC->>DotNetObject: Create(this)
DotNetObject-->>WC: DotNetObjectReference
WC->>JS: InvokeVoidAsync("ping", "ip.axd", DotNetObjectReference, "SetData")
JS->>Server: GET ip.axd
alt Request succeeds
Server-->>JS: {Ip: ...}
JS->>JS: localStorage.getItem('bb_hub_connection_id')
JS->>JS: browser()
JS-->>WC: ClientInfo
else Request fails
Server-->>JS: Error
JS-->>WC: ClientInfo
end
WC->>WC: _taskCompletionSource.Task.WaitAsync(TimeSpan.FromSeconds(3))
else JSModule fails to load
JSR-->>WC: Exception
WC->>Logger: LogError(ex, "{GetClientInfo} throw exception", nameof(GetClientInfo))
end
WC-->>WC: Returns ClientInfo
Updated class diagram for WebClientServiceclassDiagram
class WebClientService {
-IJSRuntime runtime
-ILogger logger
-JSModule? _jsModule
-DotNetObjectReference _interop
-TaskCompletionSource _taskCompletionSource
+WebClientService(IJSRuntime runtime, ILogger logger, IOptionsSnapshot BootstrapBlazorOptions)
+Task<ClientInfo> GetClientInfo()
+void SetData(string ip)
}
note for WebClientService "Added exception handling in GetClientInfo method"
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ArgoZhang - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a try-catch block around the
execute
call ingetClientInfo
inclient.js
to handle potential network errors. - It looks like you're catching
ObjectDisposedException
inJSModuleExtensions.cs
, but not re-throwing it - is this intentional?
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5411 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 644 644
Lines 29330 29330
Branches 4128 4129 +1
=========================================
Hits 29330 29330 ☔ View full report in Codecov by Sentry. |
add catch exception logic
Summary of the changes (Less than 80 chars)
简单描述你更改了什么, 不超过80个字符;如果有关联 Issue 请在下方填写相关编号
Description
fixes #5410
Regression?
[If yes, specify the version the behavior has regressed from]
[是否影响老版本]
Risk
[Justify the selection above]
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
This pull request adds exception handling logic to the JavaScript module loading process and simplifies the retrieval of client information. It improves the robustness of the application by preventing crashes due to JavaScript module loading failures and streamlines the client information retrieval process.
Bug Fixes:
Enhancements:
getClientInfo
function by removing theoptions
parameter and directly calling theexecute
function to retrieve IP address information.enableIpLocator
option from theping
function in the JavaScript client module, streamlining the process of retrieving client information.