react-native-spotify icon indicating copy to clipboard operation
react-native-spotify copied to clipboard

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

Open dylancom opened this issue 3 years ago • 12 comments

dylancom avatar Aug 30 '21 16:08 dylancom

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.

Bhavin-hyperspace avatar Jul 21 '22 10:07 Bhavin-hyperspace

@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

lufinkey avatar Jul 21 '22 13:07 lufinkey

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);
});

Bhavin-hyperspace avatar Jul 21 '22 13:07 Bhavin-hyperspace

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

lufinkey avatar Jul 21 '22 13:07 lufinkey

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

Bhavin-hyperspace avatar Jul 21 '22 13:07 Bhavin-hyperspace

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

lufinkey avatar Jul 21 '22 13:07 lufinkey

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

lufinkey avatar Jul 21 '22 13:07 lufinkey

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

Bhavin-hyperspace avatar Jul 21 '22 13:07 Bhavin-hyperspace

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

lufinkey avatar Jul 21 '22 14:07 lufinkey

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

Bhavin-hyperspace avatar Aug 03 '22 10:08 Bhavin-hyperspace

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.

lufinkey avatar Aug 05 '22 15:08 lufinkey

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

Bhavin-hyperspace avatar Aug 12 '22 07:08 Bhavin-hyperspace