Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider add error type for request apple store api #229

Open
bing-h opened this issue Jul 26, 2023 · 1 comment
Open

Consider add error type for request apple store api #229

bing-h opened this issue Jul 26, 2023 · 1 comment

Comments

@bing-h
Copy link

bing-h commented Jul 26, 2023

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
}
@richzw
Copy link
Collaborator

richzw commented Jul 26, 2023

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
		}
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants