add utils.UnwrapError() to provide meaningful error messages
This commit is contained in:
@@ -68,7 +68,7 @@ func (b *Bot) Send(ctx context.Context, email *utils.Email) error {
|
||||
content := email2content(email, cfg, threadID)
|
||||
eventID, serr := b.lp.Send(roomID, content)
|
||||
if serr != nil {
|
||||
return serr
|
||||
return utils.UnwrapError(serr)
|
||||
}
|
||||
|
||||
if threadID == "" && !cfg.NoThreads() {
|
||||
|
||||
@@ -112,9 +112,9 @@ func (b *Bot) getSettings(roomID id.RoomID) (settings, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return config, err
|
||||
return config, utils.UnwrapError(err)
|
||||
}
|
||||
|
||||
func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error {
|
||||
return b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg)
|
||||
return utils.UnwrapError(b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
@@ -24,3 +25,29 @@ func RelatesTo(noThreads bool, parentID id.EventID) *event.RelatesTo {
|
||||
EventID: parentID,
|
||||
}
|
||||
}
|
||||
|
||||
// UnwrapError tries to unwrap a error into something meaningful, like mautrix.HTTPError or mautrix.RespError
|
||||
func UnwrapError(err error) error {
|
||||
switch err.(type) {
|
||||
case nil:
|
||||
return nil
|
||||
case mautrix.HTTPError:
|
||||
return unwrapHTTPError(err)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func unwrapHTTPError(err error) error {
|
||||
httperr, ok := err.(mautrix.HTTPError)
|
||||
if !ok {
|
||||
return err
|
||||
}
|
||||
|
||||
uwerr := httperr.Unwrap()
|
||||
if uwerr != nil {
|
||||
return uwerr
|
||||
}
|
||||
|
||||
return httperr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user