Forráskód Böngészése

Send bridge state if connection fails

Tulir Asokan 3 éve
szülő
commit
a99ced14fd
2 módosított fájl, 26 hozzáadás és 14 törlés
  1. 19 14
      bridgestate.go
  2. 7 0
      user.go

+ 19 - 14
bridgestate.go

@@ -47,23 +47,25 @@ const (
 type BridgeErrorCode string
 
 const (
-	WALoggedOut     BridgeErrorCode = "wa-logged-out"
-	WAAccountBanned BridgeErrorCode = "wa-account-banned"
-	WAUnknownLogout BridgeErrorCode = "wa-unknown-logout"
-	WANotConnected  BridgeErrorCode = "wa-not-connected"
-	WAConnecting    BridgeErrorCode = "wa-connecting"
-	WAServerTimeout BridgeErrorCode = "wa-server-timeout"
-	WAPhoneOffline  BridgeErrorCode = "wa-phone-offline"
+	WALoggedOut        BridgeErrorCode = "wa-logged-out"
+	WAAccountBanned    BridgeErrorCode = "wa-account-banned"
+	WAUnknownLogout    BridgeErrorCode = "wa-unknown-logout"
+	WANotConnected     BridgeErrorCode = "wa-not-connected"
+	WAConnecting       BridgeErrorCode = "wa-connecting"
+	WAServerTimeout    BridgeErrorCode = "wa-server-timeout"
+	WAPhoneOffline     BridgeErrorCode = "wa-phone-offline"
+	WAConnectionFailed BridgeErrorCode = "wa-connection-failed"
 )
 
 var bridgeHumanErrors = map[BridgeErrorCode]string{
-	WALoggedOut:     "You were logged out from another device. Relogin to continue using the bridge.",
-	WAAccountBanned: "Your account was banned from WhatsApp. You can contact support from the WhatsApp mobile app on your phone.",
-	WAUnknownLogout: "You were logged out for an unknown reason. Relogin to continue using the bridge.",
-	WANotConnected:  "You're not connected to WhatsApp",
-	WAConnecting:    "Reconnecting to WhatsApp...",
-	WAServerTimeout: "The WhatsApp web servers are not responding. The bridge will try to reconnect.",
-	WAPhoneOffline:  "Your phone hasn't been seen in over 12 days. The bridge is currently connected, but will get disconnected if you don't open the app soon.",
+	WALoggedOut:        "You were logged out from another device. Relogin to continue using the bridge.",
+	WAAccountBanned:    "Your account was banned from WhatsApp. You can contact support from the WhatsApp mobile app on your phone.",
+	WAUnknownLogout:    "You were logged out for an unknown reason. Relogin to continue using the bridge.",
+	WANotConnected:     "You're not connected to WhatsApp",
+	WAConnecting:       "Reconnecting to WhatsApp...",
+	WAServerTimeout:    "The WhatsApp web servers are not responding. The bridge will try to reconnect.",
+	WAPhoneOffline:     "Your phone hasn't been seen in over 12 days. The bridge is currently connected, but will get disconnected if you don't open the app soon.",
+	WAConnectionFailed: "Connecting to the WhatsApp web servers failed.",
 }
 
 type BridgeState struct {
@@ -78,6 +80,9 @@ type BridgeState struct {
 	UserID     id.UserID `json:"user_id,omitempty"`
 	RemoteID   string    `json:"remote_id,omitempty"`
 	RemoteName string    `json:"remote_name,omitempty"`
+
+	Reason string                 `json:"reason,omitempty"`
+	Info   map[string]interface{} `json:"info,omitempty"`
 }
 
 type GlobalBridgeState struct {

+ 7 - 0
user.go

@@ -375,6 +375,13 @@ func (user *User) Connect() bool {
 	err := user.Client.Connect()
 	if err != nil {
 		user.log.Warnln("Error connecting to WhatsApp:", err)
+		user.sendBridgeState(BridgeState{
+			StateEvent: StateUnknownError,
+			Error:      WAConnectionFailed,
+			Info: map[string]interface{}{
+				"go_error": err.Error(),
+			},
+		})
 		return false
 	}
 	return true