feat: add ErrNoSuchMessage to pmapi

This commit is contained in:
James Houlahan 2020-04-16 17:32:30 +02:00 committed by Jakub Cuth
parent d1e63254f2
commit e1ecc11f38
5 changed files with 12 additions and 1 deletions

View File

@ -15,6 +15,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
* GODT-282 Completely delete old draft instead moving to trash when user updates draft
* Adding DSN Sentry as build time parameter
* GODT-124 bump go-appdir from v1.0.0 to v1.1.0
* Skip processing message update event if http statuscode is 422
## [v1.2.6] Donghai - beta (2020-03-XXX)

View File

@ -431,7 +431,7 @@ func (loop *eventLoop) processMessages(eventLog *logrus.Entry, messages []*pmapi
msgLog.WithError(err).Warning("Message was not present in DB. Trying fetch...")
if msg, err = loop.store.fetchMessage(message.ID); err != nil {
if err != pmapi.ErrAPINotReachable {
if err == pmapi.ErrNoSuchMessage {
msgLog.WithError(err).Warn("Skipping message update because message exists neither in local DB nor on API")
err = nil
continue

View File

@ -56,6 +56,8 @@ var (
ErrInvalidToken = errors.New("refresh token invalid")
ErrAPINotReachable = errors.New("cannot reach the server")
ErrUpgradeApplication = errors.New("application upgrade required")
ErrNoSuchMessage = errors.New("no such message")
)
type ErrUnauthorized struct {

View File

@ -532,7 +532,13 @@ func (c *Client) GetMessage(id string) (msg *Message, err error) {
return
}
if res.StatusCode == http.StatusUnprocessableEntity {
err = ErrNoSuchMessage
return
}
msg, err = res.Message, res.Err()
return
}

View File

@ -17,6 +17,8 @@
package pmapi
import "net/http"
// Common response codes.
const (
CodeOk = 1000