apple / app-store-server-library-java

MIT License
166 stars 38 forks source link

Jackson cannot deserialize error payload when HTTP status code is 401 #83

Closed at9pm closed 3 months ago

at9pm commented 7 months ago

I was running locally in JDK21 with environment Xcode / LocalTesting. When I try to getTransactionHistory, if there is abnormal HTTP status code, jackson cannot deserialize it to ErrorPayload.class. 404 can deserialize, but 401 cannot. It should be due to HTTP 401 has an empty response body.

com.apple.itunes.storekit.client.APIException: Failed to call API with httpStatusCode=401
    at com.apple.itunes.storekit.client.AppStoreServerAPIClient.makeHttpCall(AppStoreServerAPIClient.java:132) ~[app-store-server-library-1.1.0.jar:na]
    at com.apple.itunes.storekit.client.AppStoreServerAPIClient.getTransactionHistory(AppStoreServerAPIClient.java:287) ~[app-store-server-library-1.1.0.jar:na]
.
.
.
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
 at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 0]
    at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59) ~[jackson-databind-2.15.3.jar:2.15.3]
    at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4916) ~[jackson-databind-2.15.3.jar:2.15.3]
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4818) ~[jackson-databind-2.15.3.jar:2.15.3]
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3785) ~[jackson-databind-2.15.3.jar:2.15.3]
    at com.apple.itunes.storekit.client.AppStoreServerAPIClient.makeHttpCall(AppStoreServerAPIClient.java:126) ~[app-store-server-library-1.1.0.jar:na]
alexanderjordanbaker commented 7 months ago

Yes, 401 may have an empty response body, in which case you get a status code of 401 without a body

at9pm commented 7 months ago

Perhaps it can be a low priority task to enhance the error handling. Although it is 401, it should not induce a deserialization error. I was a little bit confused at first before I figured out I requested to a wrong enviroment, thus 401.