Return errors from JSON encode/decode
I found two JSON errors being shadowed; the one in amazon/validator.go is being hidden by errors.New(responseError.Message) -- which should be an empty string if there's a JSON error. So, it wouldn't report success, but this gives the caller better information on what failed. The second is in appstore/validator.go, which was ignoring encode errors before POSTing a verify request.
This commit is contained in:
@@ -102,6 +102,9 @@ func (c *Client) Verify(ctx context.Context, userID string, receiptID string) (I
|
|||||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
responseError := IAPResponseError{}
|
responseError := IAPResponseError{}
|
||||||
err = json.NewDecoder(resp.Body).Decode(&responseError)
|
err = json.NewDecoder(resp.Body).Decode(&responseError)
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
return result, errors.New(responseError.Message)
|
return result, errors.New(responseError.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,9 @@ func NewWithClient(client *http.Client) *Client {
|
|||||||
// Verify sends receipts and gets validation result
|
// Verify sends receipts and gets validation result
|
||||||
func (c *Client) Verify(ctx context.Context, reqBody IAPRequest, result interface{}) error {
|
func (c *Client) Verify(ctx context.Context, reqBody IAPRequest, result interface{}) error {
|
||||||
b := new(bytes.Buffer)
|
b := new(bytes.Buffer)
|
||||||
json.NewEncoder(b).Encode(reqBody)
|
if err := json.NewEncoder(b).Encode(reqBody); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", c.ProductionURL, b)
|
req, err := http.NewRequest("POST", c.ProductionURL, b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user