infinitered / apisauce

Axios + standardized errors + request/response transforms.
MIT License
2.8k stars 187 forks source link

Getting NETWORK_ERROR sometimes when requesting #181

Open amabdul opened 6 years ago

amabdul commented 6 years ago

When I try to fetch data sometimes I am getting the error, most of the time works fine. If it generate error once, the chance of occurence is high, in the immediate call.

The error log in the chrome debugger is:

{duration: 126, problem: "NETWORK_ERROR", originalError: Error: Network Error at createError (blob:http://10.0.0.59:8081/f5cf0951-79a8-4e8c-9a37-0013ae13…, ok: false, status: null, …}

react-native-cli: 2.0.1 react-native: 0.55.4

I am not getting why the error occur for the same success request. The network is reachable. Since it occur sometime its become a headache. Please help

skellock commented 6 years ago

Trying console.logging that response.originalError... that should shed some light on things. That's the underlying axios error. the status: null would mean that that server was not reached (whether that's a network issue or a server not responding, we can't really know).

amabdul commented 6 years ago

Can I implement retry logic for the same request, if I got the specific error. Would something like this work with apisauce: axios/axios#934.

skellock commented 6 years ago

You can access the axiosInstance after creating an api by doing api.axiosInstance. That way you have full access to everything they can do.

amabdul commented 6 years ago

hi I wrote like this

api.axiosInstance.interceptors.response.use(function (response) { if (response.data) { // for NETWORK_ERROR data will be null console.log('interceptors response success', response) } else { console.log('interceptors response error', response) return api.axiosInstance.request(response.config); } return response; }, function (error) { return Promise.reject(error); })

I always get log 'interceptors response success' for fine calls. But nothing got logged for NETWORK_ERROR. Means not intercepted for this error. Why is that?

skellock commented 6 years ago

I believe axios treats that as an exception, so perhaps doesn't take the interception route home? I haven't tried that before so I can't say for sure.

amabdul commented 6 years ago

how we can effectively debug the issue. to find who is responsible for the error is it the apisause OR actually the server do apisause has the issue "for some request whether it end up in NETWORK_ERROR"

skellock commented 6 years ago

NETWORK_ERROR is set from apisauce. It makes that decision by investigating the response value from the axios exception. That's the originalError property that comes back when you make that call.

Everything that apisauce knows comes from that, so if you have a look at that error message and stack trace closely, that might give you some more info.

In your original post, I see something like blob in there. That's the new blob support that's in React Native 53 or 54 (I can't remember), so that's throwing a little bit of obfuscation into the mix as well.

Getting access to the server logs can help too (not sure if that's an option for you or not).

Lack of a good error message certain is frustrating to track down.

keerthi0611 commented 5 years ago

When I try to fetch data sometimes I am getting the error, most of the time works fine. If it generate error once, the chance of occurence is high, in the immediate call.

The error log in the chrome debugger is:

{duration: 126, problem: "NETWORK_ERROR", originalError: Error: Network Error at createError (blob:http://10.0.0.59:8081/f5cf0951-79a8-4e8c-9a37-0013ae13…, ok: false, status: null, …}

react-native-cli: 2.0.1 react-native: 0.55.4

I am not getting why the error occur for the same success request. The network is reachable. Since it occur sometime its become a headache. Please help

Even i am facing the same issue...........

keerthi0611 commented 5 years ago

Can someone please post the solution if u get any info about this?

cassiossantos commented 5 years ago

Check your network connection... I had the same problem hahaha

waleedarshad commented 5 years ago

I am having same issue @keerthi0611 are you able to solve it?

cassiossantos commented 5 years ago

@waleedarshad Check your network connection . Maybe your device is disconnected.

fuavix commented 5 years ago

My network is good, but I still get "problem":"NETWORK_ERROR" "status": null

ivandomar commented 4 years ago

Guys, sadly I'm here for the same reason. NETWORK_ERROR pops out without any clue. I've noticed that it depends on the machine whom listens the requests. But couldn't realize any possible cause.

dekameron22 commented 4 years ago

+1

YashYash commented 4 years ago

+1

PecoCaballero commented 4 years ago
mabecth commented 4 years ago

I get the NETWORK_ERROR in react-native v0.61.5 on iOS if I minimize the app during the request before a response is received. The request however still reaches the server but axios reports an NETWORK_ERROR with status: null. Any ideas why this happens and how to solve it?

HassanRazaMuhammadTufail commented 4 years ago

I have same issue NETWORK_ERROR with status: null

RaviTeja-94 commented 4 years ago

I facing the same NETWORK_ERROR problem ,

"originalError": [Error: Network Error],
  "problem": "NETWORK_ERROR",
  "status": null,
goltaraguilherme commented 4 years ago

I had same issue NETWORK_ERROR status: null. So, You should try: ipconfig in powershell and get the ipv4. You have to change localhost:port to your ipv4:port

augini commented 4 years ago

THE SOLUTION is: on Android you need to specify the file path with file:// as prefix. So do like this:

      const audio = {
        uri: 'file://' + this.recorder.fsPath,
        type: 'video/mp4',
        name: filename
      }

Good Luck

Marianbc commented 3 years ago

Had this issue. I was following a tutorial that was using an emulator, but I was using a real device for my testing. ipconfig to get your IPv4 for your apisauce client baseURL. such as: baseURL: "http://199.199.9.90:8000/api", setup your django API not on localhost (as this can't be accessed from a real device). python manage.py runserver 0.0.0.0:8000 good luck!

absmugz commented 3 years ago

@amabdul did you come right ? so we can close this ?

farzan106 commented 3 years ago

I have the same issue, even in my baseURL I have used my machine ipv4 address instead of localhost but still the problem remains

Fraser123456 commented 3 years ago

So I had a similar issue and it was because I was sending the date to my APS .net backend but the date wasn't in a string format. When I converted my date to a string then the request went through.

anicetfosso commented 1 year ago

Check the data, I had the same problem and noticed that a variable in my data was undefined

TarSandorr commented 1 year ago

Well, I tried all of the possibilities, I used the correct IPv4, IPv6, './listings/, localhost. I also downloaded the zipped files and tried them, every time I got “problem”: “NETWORK_ERROR”. Is there somebody who resolved the problem?

The response of the request: Object { “config”: Object { “adapter”: [Function xhrAdapter], “baseURL”: “http://192.168.0.10:9000/api”, “data”: undefined, “headers”: Object { “Accept”: “application/json”, }, “maxContentLength”: -1, “method”: “get”, “params”: Object {}, “timeout”: 0, “transformRequest”: Array [ [Function transformRequest], ], “transformResponse”: Array [ [Function transformResponse], ], “url”: “/listings”, “validateStatus”: [Function validateStatus], “xsrfCookieName”: “XSRF-TOKEN”, “xsrfHeaderName”: “X-XSRF-TOKEN”, }, “data”: null, “duration”: 69619, “headers”: null, “ok”: false, “originalError”: [Error: Network Error], “problem”: “NETWORK_ERROR”, “status”: null, }

uxinnuendo commented 1 year ago

So I had a similar issue and it was because I was sending the date to my APS .net backend but the date wasn't in a string format. When I converted my date to a string then the request went through.

Same here, apisauce doesnt even send the request at all, just returns NETWORK_ERROR because the payload is malformed - needs better handling.