forked from Silverfish/proton-bridge
fix: better error messages for 422
This commit is contained in:
@ -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...")
|
msgLog.WithError(err).Warning("Message was not present in DB. Trying fetch...")
|
||||||
|
|
||||||
if msg, err = loop.apiClient.GetMessage(message.ID); err != nil {
|
if msg, err = loop.apiClient.GetMessage(message.ID); err != nil {
|
||||||
if err == pmapi.ErrNoSuchAPIID {
|
if _, ok := err.(*pmapi.ErrUnprocessableEntity); ok {
|
||||||
msgLog.WithError(err).Warn("Skipping message update because message exists neither in local DB nor on API")
|
msgLog.WithError(err).Warn("Skipping message update because message exists neither in local DB nor on API")
|
||||||
err = nil
|
err = nil
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -56,10 +56,16 @@ var (
|
|||||||
ErrInvalidToken = errors.New("refresh token invalid")
|
ErrInvalidToken = errors.New("refresh token invalid")
|
||||||
ErrAPINotReachable = errors.New("cannot reach the server")
|
ErrAPINotReachable = errors.New("cannot reach the server")
|
||||||
ErrUpgradeApplication = errors.New("application upgrade required")
|
ErrUpgradeApplication = errors.New("application upgrade required")
|
||||||
|
|
||||||
ErrNoSuchAPIID = errors.New("no such API ID")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ErrUnprocessableEntity struct {
|
||||||
|
error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err *ErrUnprocessableEntity) Error() string {
|
||||||
|
return err.error.Error()
|
||||||
|
}
|
||||||
|
|
||||||
type ErrUnauthorized struct {
|
type ErrUnauthorized struct {
|
||||||
error
|
error
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,11 @@
|
|||||||
|
|
||||||
package pmapi
|
package pmapi
|
||||||
|
|
||||||
import "net/http"
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
// Common response codes.
|
// Common response codes.
|
||||||
const (
|
const (
|
||||||
@ -38,7 +42,7 @@ type Res struct {
|
|||||||
// Err returns error if the response is an error. Otherwise, returns nil.
|
// Err returns error if the response is an error. Otherwise, returns nil.
|
||||||
func (res Res) Err() error {
|
func (res Res) Err() error {
|
||||||
if res.StatusCode == http.StatusUnprocessableEntity {
|
if res.StatusCode == http.StatusUnprocessableEntity {
|
||||||
return ErrNoSuchAPIID
|
return &ErrUnprocessableEntity{errors.New(res.Error)}
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.ResError == nil {
|
if res.ResError == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user