go-iap icon indicating copy to clipboard operation
go-iap copied to clipboard

Consider add error type for request apple store api

Open bing-h opened this issue 1 year ago • 1 comments

for example,function GetALLSubscriptionStatuses return (rsp *StatusResponse, err error) ,I hope to retry when apple server return response code 429, maybe return custom error type with field status.

type AppstoreAPIError struct {
	err        error
	statusCode int
}

bing-h avatar Jul 26 '23 11:07 bing-h

The errCode == 4290000 could meet your requirement, please refer to codes https://github.com/awa/go-iap/blob/master/appstore/api/error.go#L43

func newAppStoreAPIError(b []byte, hd http.Header) (*Error, bool) {
	if len(b) == 0 {
		return nil, false
	}
	var rErr appStoreAPIErrorResp
	if err := json.Unmarshal(b, &rErr); err != nil {
		return nil, false
	}
	if rErr.ErrorCode == 0 {
		return nil, false
	}
	if rErr.ErrorCode == 4290000 {
		retryAfter, err := strconv.ParseInt(hd.Get("Retry-After"), 10, 64)
		if err == nil {
			return &Error{errorCode: rErr.ErrorCode, errorMessage: rErr.ErrorMessage, retryAfter: retryAfter}, true
		}
	}

richzw avatar Jul 26 '23 11:07 richzw