lufinkey/react-native-spotify

Error: The data couldn’t be read because it isn’t in the correct format.

dylancom opened this issue · 12 comments

Error: The data couldn’t be read because it isn’t in the correct format.

Suddenly i faced this issue in iOS. It works normally when i running the app but after sometimes on each api call i got this error.
Error: The data couldn’t be read because it isn’t in the correct format.

@thbhavin1986 if you could include the actual API endpoints the data sent, and the raw response string before it gets parsed that would be very helpful in finding the issue. You could probably log the native response string in the native code of the module

Screenshot 2022-07-21 at 5 02 28 PM
@lufinkey I debug the native code and got the response as per above screenshot.
Endpoint: I tried to fetch "v1/me"

Spotify.getMe().then(getMeRes => {
          console.log('getMeRes =>', getMeRes.id);
});

Could you include the rest of the response as well? Not just the headers

<NSHTTPURLResponse: 0x600000ce7b20> { URL: https://api.spotify.com/v1/me } { Status Code: 429, Headers {
    "Access-Control-Allow-Origin" =     (
        "*"
    );
    "Alt-Svc" =     (
        "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
    );
    "Cache-Control" =     (
        "private, max-age=0"
    );
    "Content-Encoding" =     (
        gzip
    );
    Date =     (
        "Thu, 21 Jul 2022 11:25:10 GMT"
    );
    Server =     (
        envoy
    );
    "Strict-Transport-Security" =     (
        "max-age=31536000"
    );
    "Transfer-Encoding" =     (
        Identity
    );
    Via =     (
        "HTTP/2 edgeproxy, 1.1 google"
    );
    "access-control-allow-credentials" =     (
        true
    );
    "access-control-allow-headers" =     (
        "Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context, client-token, content-access-token"
    );
    "access-control-allow-methods" =     (
        "GET, POST, OPTIONS, PUT, DELETE, PATCH"
    );
    "access-control-max-age" =     (
        604800
    );
    "retry-after" =     (
        64350
    );
    "x-content-type-options" =     (
        nosniff
    );
} }

This is the actual response which i received from Spotify api.

result = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
In above statement i got data object as "nil".

Is there no body of the response? I bet it's trying to parse Json that isn't there

I'll try to make push a change when I get the chance.

Is there no body of the response? I bet it's trying to parse Json that isn't there

Yes there is no body of the response

This function is simply sending an HTTP request to the spotify API, so you should be able to grab the session data and make the request yourself if needed. I'll update when I have some time though

Hello @lufinkey
Did you get a chance to solve this issue?
Thanks

sorry I've been pretty busy. I've set a few reminders on my phone to look at github stuff, so I'll try to get to it this weekend. Feel free to keep bugging me at this point though if it's urgent as I tend to forget things.

Hello @lufinkey
Did you get a chance to solve this issue?
Thanks