-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Do not throw warnings when a service calls disconnects the websocket #8932
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { | |
| callService, | ||
| Connection, | ||
| ERR_INVALID_AUTH, | ||
| ERR_CONNECTION_LOST, | ||
| HassConfig, | ||
| subscribeConfig, | ||
| subscribeEntities, | ||
|
|
@@ -13,6 +14,7 @@ import { broadcastConnectionStatus } from "../data/connection-status"; | |
| import { subscribeFrontendUserData } from "../data/frontend"; | ||
| import { forwardHaptic } from "../data/haptics"; | ||
| import { DEFAULT_PANEL } from "../data/panel"; | ||
| import { serviceCallWillDisconnect } from "../data/service"; | ||
| import { NumberFormat } from "../data/translation"; | ||
| import { subscribePanels } from "../data/ws-panels"; | ||
| import { translationMetadata } from "../resources/translations-metadata"; | ||
|
|
@@ -78,6 +80,12 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>( | |
| target | ||
| )) as Promise<ServiceCallResponse>; | ||
| } catch (err) { | ||
| if ( | ||
| err.error.code === ERR_CONNECTION_LOST && | ||
| serviceCallWillDisconnect(domain, service) | ||
| ) { | ||
| throw err; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throw? Not return?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure how all the existing callers would handle it if they got back nothing instead of the promise so throw + suppressing the notification in the UI seemed like the way to go. Better ideas?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think almost nothing in the frontend uses the return value of If we throw, it will not be caught by the caller, as we previously never thrown errors, but caught errors here. I would return undefined to keep current behavior.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (and move it after the dev console log)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! and Good night! |
||
| } | ||
| if (__DEV__) { | ||
| // eslint-disable-next-line no-console | ||
| console.error( | ||
|
|
||
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.
This can also work:
(but is less readable)