You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: appstore/validator.go
+35-22
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@ import (
5
5
"context"
6
6
"encoding/json"
7
7
"errors"
8
+
"fmt"
8
9
"io/ioutil"
9
10
"net/http"
10
11
"time"
@@ -33,47 +34,53 @@ type Client struct {
33
34
httpCli*http.Client
34
35
}
35
36
37
+
var (
38
+
ErrAppStoreServer=errors.New("AppStore server error")
39
+
40
+
ErrInvalidJSON=errors.New("The App Store could not read the JSON object you provided.")
41
+
ErrInvalidReceiptData=errors.New("The data in the receipt-data property was malformed or missing.")
42
+
ErrReceiptUnauthenticated=errors.New("The receipt could not be authenticated.")
43
+
ErrInvalidSharedSecret=errors.New("The shared secret you provided does not match the shared secret on file for your account.")
44
+
ErrServerUnavailable=errors.New("The receipt server is not currently available.")
45
+
ErrReceiptIsForTest=errors.New("This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead.")
46
+
ErrReceiptIsForProduction=errors.New("This receipt is from the production environment, but it was sent to the test environment for verification. Send it to the production environment instead.")
47
+
ErrReceiptUnauthorized=errors.New("This receipt could not be authorized. Treat this the same as if a purchase was never made.")
48
+
49
+
ErrInternalDataAccessError=errors.New("Internal data access error.")
// HandleError returns error message by status code
37
54
funcHandleError(statusint) error {
38
-
varmessagestring
39
-
55
+
vareerror
40
56
switchstatus {
41
57
case0:
42
58
returnnil
43
-
44
59
case21000:
45
-
message="The App Store could not read the JSON object you provided."
46
-
60
+
e=ErrInvalidJSON
47
61
case21002:
48
-
message="The data in the receipt-data property was malformed or missing."
49
-
62
+
e=ErrInvalidReceiptData
50
63
case21003:
51
-
message="The receipt could not be authenticated."
52
-
64
+
e=ErrReceiptUnauthenticated
53
65
case21004:
54
-
message="The shared secret you provided does not match the shared secret on file for your account."
55
-
66
+
e=ErrInvalidSharedSecret
56
67
case21005:
57
-
message="The receipt server is not currently available."
58
-
68
+
e=ErrServerUnavailable
59
69
case21007:
60
-
message="This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead."
61
-
70
+
e=ErrReceiptIsForTest
62
71
case21008:
63
-
message="This receipt is from the production environment, but it was sent to the test environment for verification. Send it to the production environment instead."
64
-
72
+
e=ErrReceiptIsForProduction
65
73
case21010:
66
-
message="This receipt could not be authorized. Treat this the same as if a purchase was never made."
out: errors.New("The App Store could not read the JSON object you provided."),
29
+
out: ErrInvalidJSON,
30
30
},
31
31
{
32
32
name: "status 21002",
33
33
in: 21002,
34
-
out: errors.New("The data in the receipt-data property was malformed or missing."),
34
+
out: ErrInvalidReceiptData,
35
35
},
36
36
{
37
37
name: "status 21003",
38
38
in: 21003,
39
-
out: errors.New("The receipt could not be authenticated."),
39
+
out: ErrReceiptUnauthenticated,
40
40
},
41
41
{
42
42
name: "status 21004",
43
43
in: 21004,
44
-
out: errors.New("The shared secret you provided does not match the shared secret on file for your account."),
44
+
out: ErrInvalidSharedSecret,
45
45
},
46
46
{
47
47
name: "status 21005",
48
48
in: 21005,
49
-
out: errors.New("The receipt server is not currently available."),
49
+
out: ErrServerUnavailable,
50
50
},
51
51
{
52
52
name: "status 21007",
53
53
in: 21007,
54
-
out: errors.New("This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead."),
54
+
out: ErrReceiptIsForTest,
55
55
},
56
56
{
57
57
name: "status 21008",
58
58
in: 21008,
59
-
out: errors.New("This receipt is from the production environment, but it was sent to the test environment for verification. Send it to the production environment instead."),
59
+
out: ErrReceiptIsForProduction,
60
60
},
61
61
{
62
62
name: "status 21010",
63
63
in: 21010,
64
-
out: errors.New("This receipt could not be authorized. Treat this the same as if a purchase was never made."),
0 commit comments