React Native fetch different result with/without wifi

Viewed 898

I experienced some strange behaviour testing my ReactNative-App on my device. Where you might be able to tell me what i am doing wrong.

Frist of all I have a REST-API returning a list of posts. Here some output requested with postman (it is the same url as later on in the app):

{
    "status": 200,
    "data": [
        {
            "id": "6bb373c6dbe8c4782121068223a1d5bf710a14a62943443bdc5c017ce873935a",
            "description": "",
            "upvotes": 0,
            "downvotes": 0,
            "creationTime": "2017-08-16T04:44:03Z"
        },
        {
            "id": "5ae791aa33512dc179f075649f68731f269c366a37807f7da9eeeabafcda8c7d",
            "description": "",
            "upvotes": 0,
            "downvotes": 0,
            "creationTime": "2017-08-16T04:42:27Z"
        },
    ],
    "version": "0.0.1",
    "servertime": "2017-08-16T07:02:32.250978864+02:00"
}

I would expect to obtain this object over wifi and mobile internet.

Here the codesnipped for requesting my API inside my app:

exports.getPosts = function() {
    return fetch(HTTP.baseurl + "/image", {
        method: "GET"
    }).then(res => res.json()).then((res)=>{
        //this is the line you will see the output from
        console.log(JSON.stringify(res, null, 2));
        return res
    });
}

If request the API with wifi I get the same object as in postman. But if requested with mobile internet I get the following object:

{
    "status": 200,
    "data": {
        "id": "5ae791aa33512dc179f075649f68731f269c366a37807f7da9eeeabafcda8c7d",
        "description": "",
        "upvotes": 0,
        "downvotes": 0,
        "creationTime": "2017-08-16T06:42:27.37228137+02:00"
    },
    "version": "0.0.1",
    "servertime": "2017-08-16T06:42:27.4874009+02:00"
}

Tested on:

macOS:        10.12.6
XCode:         8.3.3
iOS:          10.3.3 (iPhone 6)
node:          8.4.0
react:        16.0.0-alpha.12
react-native:  0.45.1

EDIT:

I also reproduced it on a fresh react native app only inserting following lines of code:

//first send an image to the API
fetch("http://services.impressions-app.com/test/image", {
        method: "POST",
        body: JSON.stringify({"blob": blob, "description": ""})
    }).then(res => res.json()).then(res => {
        //then request all the images including the new one
        return fetch("http://services.impressions-app.com/test/image", {
            method: "GET"
        })
    }).then(res => res.json()).then(res => {
        //should log an array of imageobjects (see postman response above)
        console.log("LOADED", res);
    }).catch(e => {
        console.error(e)
    });

I got an object like above with data as an object instead of an array:

{
    "status": 200,
    "data": {
        "id": "06c50436c2b2b671a64ce3b57b6cac76b648a83ed621305a0f6a55f8186957ba",
        "description": "",
        "upvotes": 0,
        "downvotes": 0,
        "creationTime": "2017-08-17T08:00:24.198626835+02:00"
    },
    "version": "0.0.1",
    "servertime": "2017-08-17T08:00:26.031231455+02:00"
}

Tested on:

macOS:        10.12.6
XCode:         8.3.3
iOS:          10.3.3 (iPhone 6)
node:          8.4.0
react:        16.0.0-alpha.12
react-native:  0.45.1

EDIT #2:

I watched the log files and it only logged this request when I requested over wifi. The other requests were logged as expected.

Maybe it is a caching problem?

Did anyone of you have a similar problem?

thank you very much

1 Answers
Related