mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
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...")
|
||||
|
||||
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")
|
||||
err = nil
|
||||
continue
|
||||
|
||||
@ -56,10 +56,16 @@ var (
|
||||
ErrInvalidToken = errors.New("refresh token invalid")
|
||||
ErrAPINotReachable = errors.New("cannot reach the server")
|
||||
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 {
|
||||
error
|
||||
}
|
||||
|
||||
@ -17,7 +17,11 @@
|
||||
|
||||
package pmapi
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Common response codes.
|
||||
const (
|
||||
@ -38,7 +42,7 @@ type Res struct {
|
||||
// Err returns error if the response is an error. Otherwise, returns nil.
|
||||
func (res Res) Err() error {
|
||||
if res.StatusCode == http.StatusUnprocessableEntity {
|
||||
return ErrNoSuchAPIID
|
||||
return &ErrUnprocessableEntity{errors.New(res.Error)}
|
||||
}
|
||||
|
||||
if res.ResError == nil {
|
||||
|
||||
Reference in New Issue
Block a user