fix: better error messages for 422

This commit is contained in:
James Houlahan
2020-04-21 13:13:02 +02:00
parent 68d1442a8f
commit 76b480298a
3 changed files with 15 additions and 5 deletions

View File

@ -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 {