refactor: return ErrNoSuchAPIID any time we get 422

This commit is contained in:
James Houlahan
2020-04-17 12:12:44 +02:00
parent 49a64a656c
commit c6f32192b9
5 changed files with 13 additions and 10 deletions

View File

@ -57,7 +57,7 @@ var (
ErrAPINotReachable = errors.New("cannot reach the server")
ErrUpgradeApplication = errors.New("application upgrade required")
ErrNoSuchMessage = errors.New("no such message")
ErrNoSuchAPIID = errors.New("no such API ID")
)
type ErrUnauthorized struct {

View File

@ -532,14 +532,7 @@ 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
return res.Message, res.Err()
}
type SendMessageReq struct {

View File

@ -17,6 +17,8 @@
package pmapi
import "net/http"
// Common response codes.
const (
CodeOk = 1000
@ -35,6 +37,10 @@ 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
}
if res.ResError == nil {
return nil
}