apple / app-store-server-library-java

MIT License
151 stars 38 forks source link

an exception appears with httpStatusCode=401, apiError=null, apiErrorMessage='null' #96

Closed hakusai22 closed 2 months ago

hakusai22 commented 5 months ago

When calling the getAllSubscriptionStatuses(String transactionId, Status[] status) method in a production environment, an exception occasionally occurs, httpStatusCode=401, apiError=null, apiErrorMessage='null'. All my configurations are unified. When I create the AppStoreServerAPIClient, this exception will occasionally occur. I don't understand the triggering scenario of this accidental exception.

https://developer.apple.com/documentation/appstoreserverapi/get_all_subscription_statuses

image image
2024-05-04,02:05:40,233 ERROR a73a88cd [TID: N/A] cn.lollypop.www.xxxx.utils.RpcExceptionHandler: fail
cn.lollypop.common.base.exception.LollypopServerException: APIException{httpStatusCode=401, apiError=null, apiErrorMessage='null'}
hakusai22 commented 4 months ago
    public String generateToken() {
        return JWT.create()
                .withAudience(APP_STORE_CONNECT_AUDIENCE)
                .withExpiresAt(Instant.now().plus(ChronoUnit.MINUTES.getDuration().multipliedBy(5)))
                .withIssuer(issuerId)
                .withKeyId(keyId)
                .withPayload(Map.of(BUNDLE_ID_KEY, bundleId))
                .sign(Algorithm.ECDSA256(signingKey));
    }

I see that the code for generating tokens is one-time and newly generated. Why does 401 appear?

hakusai22 commented 4 months ago

@alexanderjordanbaker hello ,If you have time, can you help me analyze this problem? Thank you. There have been a lot of 401 in the production environment recently.

pkgonan commented 4 months ago

Oh my god.

I've been experiencing this problem recently as well. And it's still happening today.

I was searching google over and over again and found the same problem here now.

I keep getting the 401 error from time to time. This seems like a bug from Apple.

hakusai22 commented 4 months ago

Oh my god.

I've been experiencing this problem recently as well. And it's still happening today.

I was searching google over and over again and found the same problem here now.

I keep getting the 401 error from time to time. This seems like a bug from Apple.

Most requests are successful, but some requests result in 401?

alexanderjordanbaker commented 3 months ago

@hakusai22 Let me take a look and get back to you

drewster99 commented 3 months ago

any update on this?

pkgonan commented 3 months ago

Oh my god. I've been experiencing this problem recently as well. And it's still happening today. I was searching google over and over again and found the same problem here now. I keep getting the 401 error from time to time. This seems like a bug from Apple.

Most requests are successful, but some requests result in 401?

Exactly, yes.

And, as a separate issue, API calls to Apple apps that are not yet set up in production also result in a 401 error. The 401 error shouldn't occur because the JWT is correct.

The official guidance from Apple says to try calling the Production API first and if the response is invalid, try calling the Sandbox API, but a 401 response doesn't seem appropriate.

alexanderjordanbaker commented 2 months ago

@hakusai22 This should be improved now, please let me know if you continue to experience this issue

hakusai22 commented 2 months ago

@hakusai22 This should be improved now, please let me know if you continue to experience this issue

image

This abnormal situation still appeared in the log today. My version is still 2.0.0

alexanderjordanbaker commented 2 months ago

@hakusai22 This is after my post?

alexanderjordanbaker commented 2 months ago

Wait that status code is 500?

hakusai22 commented 2 months ago

Wait that status code is 500?

For my business, this is a 500 exception. The official API returns 401.

hakusai22 commented 2 months ago

@hakusai22 This is after my post?

About an hour before you posted

alexanderjordanbaker commented 2 months ago

@hakusai22 I checked the logs, you were 6 minutes before the change deployed. Please let me know if you see it again now that the change is out

hakusai22 commented 2 months ago

@alexanderjordanbaker OK, I'll take a look. What's the reason?