mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-11-15 22:42:35 +01:00
Add better error messages for some send errors
This commit is contained in:
parent
1a23bfda30
commit
d4b7595b6e
2 changed files with 28 additions and 7 deletions
29
portal.go
29
portal.go
|
@ -2162,10 +2162,14 @@ func (portal *Portal) wasMessageSent(sender *User, id string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) sendErrorMessage(message string) id.EventID {
|
func (portal *Portal) sendErrorMessage(message string, confirmed bool) id.EventID {
|
||||||
|
certainty := "may not have been"
|
||||||
|
if confirmed {
|
||||||
|
certainty = "was not"
|
||||||
|
}
|
||||||
resp, err := portal.sendMainIntentMessage(event.MessageEventContent{
|
resp, err := portal.sendMainIntentMessage(event.MessageEventContent{
|
||||||
MsgType: event.MsgNotice,
|
MsgType: event.MsgNotice,
|
||||||
Body: fmt.Sprintf("\u26a0 Your message may not have been bridged: %v", message),
|
Body: fmt.Sprintf("\u26a0 Your message %s bridged: %v", certainty, message),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Warnfln("Failed to send bridging error message:", err)
|
portal.log.Warnfln("Failed to send bridging error message:", err)
|
||||||
|
@ -2213,13 +2217,30 @@ func (portal *Portal) sendRaw(sender *User, evt *event.Event, info *waProto.WebM
|
||||||
portal.sendDeliveryReceipt(evt.ID)
|
portal.sendDeliveryReceipt(evt.ID)
|
||||||
} else {
|
} else {
|
||||||
portal.log.Warnfln("Response when bridging Matrix event %s is taking long to arrive", evt.ID)
|
portal.log.Warnfln("Response when bridging Matrix event %s is taking long to arrive", evt.ID)
|
||||||
errorEventID = portal.sendErrorMessage("message sending timed out")
|
errorEventID = portal.sendErrorMessage("message sending timed out", false)
|
||||||
}
|
}
|
||||||
err = <-errChan
|
err = <-errChan
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
var statusErr whatsapp.StatusResponse
|
||||||
|
errors.As(err, &statusErr)
|
||||||
|
var confirmed bool
|
||||||
|
var errMsg string
|
||||||
|
switch statusErr.Status {
|
||||||
|
case 400:
|
||||||
|
portal.log.Errorfln("400 response handling Matrix event %s: %+v", evt.ID, statusErr.Extra)
|
||||||
|
errMsg = "WhatsApp rejected the message (status code 400)."
|
||||||
|
if info.Message.ImageMessage != nil || info.Message.VideoMessage != nil || info.Message.AudioMessage != nil || info.Message.DocumentMessage != nil {
|
||||||
|
errMsg += " The attachment type you sent may be unsupported."
|
||||||
|
}
|
||||||
|
confirmed = true
|
||||||
|
case 599:
|
||||||
|
errMsg = "WhatsApp rate-limited the message (status code 599)."
|
||||||
|
default:
|
||||||
portal.log.Errorfln("Error handling Matrix event %s: %v", evt.ID, err)
|
portal.log.Errorfln("Error handling Matrix event %s: %v", evt.ID, err)
|
||||||
portal.sendErrorMessage(err.Error())
|
errMsg = err.Error()
|
||||||
|
}
|
||||||
|
portal.sendErrorMessage(errMsg, confirmed)
|
||||||
} else {
|
} else {
|
||||||
portal.log.Debugfln("Handled Matrix event %s", evt.ID)
|
portal.log.Debugfln("Handled Matrix event %s", evt.ID)
|
||||||
portal.sendDeliveryReceipt(evt.ID)
|
portal.sendDeliveryReceipt(evt.ID)
|
||||||
|
|
4
user.go
4
user.go
|
@ -760,7 +760,7 @@ func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, chat Chat, j
|
||||||
if lastMessage != nil {
|
if lastMessage != nil {
|
||||||
err := intent.MarkReadWithContent(chat.Portal.MXID, lastMessage.MXID, &CustomReadReceipt{DoublePuppet: true})
|
err := intent.MarkReadWithContent(chat.Portal.MXID, lastMessage.MXID, &CustomReadReceipt{DoublePuppet: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
user.log.Warnln("Failed to mark %s in %s as read after backfill: %v", lastMessage.MXID, chat.Portal.MXID, err)
|
user.log.Warnfln("Failed to mark %s in %s as read after backfill: %v", lastMessage.MXID, chat.Portal.MXID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if chat.UnreadCount == -1 {
|
} else if chat.UnreadCount == -1 {
|
||||||
|
@ -1236,7 +1236,7 @@ func (user *User) HandleMsgInfo(info whatsapp.JSONMsgInfo) {
|
||||||
|
|
||||||
err := intent.MarkReadWithContent(portal.MXID, msg.MXID, &CustomReadReceipt{DoublePuppet: intent.IsCustomPuppet})
|
err := intent.MarkReadWithContent(portal.MXID, msg.MXID, &CustomReadReceipt{DoublePuppet: intent.IsCustomPuppet})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
user.log.Warnln("Failed to mark message %s as read by %s: %v", msg.MXID, info.SenderJID, err)
|
user.log.Warnfln("Failed to mark message %s as read by %s: %v", msg.MXID, info.SenderJID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue