app-store-server-library-java icon indicating copy to clipboard operation
app-store-server-library-java copied to clipboard

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

Open hakusai22 opened this issue 1 year ago • 2 comments

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 avatar May 04 '24 03:05 hakusai22

    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 avatar May 13 '24 01:05 hakusai22

@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.

hakusai22 avatar May 22 '24 01:05 hakusai22

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.

pkgonan avatar May 31 '24 01:05 pkgonan

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?

hakusai22 avatar May 31 '24 01:05 hakusai22

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

alexanderjordanbaker avatar Jun 06 '24 05:06 alexanderjordanbaker

any update on this?

drewster99 avatar Jun 19 '24 23:06 drewster99

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.

pkgonan avatar Jun 20 '24 02:06 pkgonan

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

alexanderjordanbaker avatar Jul 08 '24 19:07 alexanderjordanbaker

@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

hakusai22 avatar Jul 08 '24 23:07 hakusai22

@hakusai22 This is after my post?

alexanderjordanbaker avatar Jul 08 '24 23:07 alexanderjordanbaker

Wait that status code is 500?

alexanderjordanbaker avatar Jul 08 '24 23:07 alexanderjordanbaker

Wait that status code is 500?

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

hakusai22 avatar Jul 08 '24 23:07 hakusai22

@hakusai22 This is after my post?

About an hour before you posted

hakusai22 avatar Jul 08 '24 23:07 hakusai22

@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

alexanderjordanbaker avatar Jul 10 '24 00:07 alexanderjordanbaker

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

hakusai22 avatar Jul 10 '24 01:07 hakusai22

I would advise everyone to go through this official video provided by apple, to handle server api. i was able to send test notification by following this video. app store server library

shubham-scaletech avatar Jan 29 '25 11:01 shubham-scaletech