React Native Error: Request failed with status code 499 - react-native

I'm trying to fetch data from an API hosted on Heroku in a React Native app on an IOS simulator, and I keep getting this error Error: Request failed with status code 499 which occurs after a long period of time (close to a minute) from the time the API call is initiated.
The same API calls work well in Android emulator.
Please what could be causing this how can I fix it?

If anybody is still experiencing these issues, make sure that you're not sending a body in your get requests. I had the issue where I sent a GET request with
{
method: 'GET',
url: '<url>',
body: {}
}
because the body was accidentally appended to the request.

Related

Netlify deployment - 500 Internal Server Error. on one pages

Im trying to deploy my app with Netlify and Heroku.
Deployment works just fine - this is the URL:
https://fahrzeugliste-t5-kfz-neumayer.netlify.app/
Start page is working as intended, while clicking on "Fahrzeugliste" gets an 500 Internal Server Error.
This is the git repo for it:
https://github.com/TimoScheiler/fahrzeugliste
Your function log here: https://app.netlify.com/sites/fahrzeugliste-t5-kfz-neumayer/functions/___netlify-handler, shows the problem. It says:
FetchError: invalid json response body at https://fahrzeugliste-t5.herokuapp.com/api/fahrzeug reason: Unexpected token < in JSON at position 0
at /var/task/node_modules/node-fetch/lib/index.js:273:32
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async getServerSideProps (/var/task/.next/server/pages/fahrzeuge.js:234:34)
at async Object.renderToHTML (/var/task/node_modules/next/dist/server/render.js:428:24)
at async doRender (/var/task/node_modules/next/dist/server/next-server.js:1149:38)
at async /var/task/node_modules/next/dist/server/next-server.js:1241:28
at async /var/task/node_modules/next/dist/server/response-cache.js:64:36 {
type: 'invalid-json'
}
If you go here: https://fahrzeugliste-t5.herokuapp.com/api/fahrzeug, you can indeed see that you don't get an expected response from your Heroku backend. You get a HTML page instead of a JSON response. You need to sort that out.

XHR is not being logged when request is being made using fetchJson, NextJS

We are using the NextJS framework in which a request is being made using 'fetchJson'. But, the issue is that the XHR request is not being logged by cypress.
Below is the logs displayed in the 'Network' - the address request is being made and it received 200. The logic in the programming is that when I enter Pincode that matches length 6, the fetchJson method is being called which makes the request.
Here is my code for my test case:
it("Validate Error message for PinCode ",function(){
cy.server({
method: "POST"
});
cy.route("POST","/api/address").as("mypin");
cy.get("form").within(()=>{
cy.get("[name='clientStreetNo']").type("Street");
cy.get("[name='clientStreetName']").type("StreetName");
cy.get("[name='clientArea']").type("are");
cy.get("[name='clientPinCode']").type("500082");
Here is a screenshot of test execution; it shows address request being made, in the network tab.
I have tried multiple ways to make cypress log the xhr request but it done;t log. How can i make the request log?

API call works locally, but fails when deployed to heroku or zeit

The HTTP GET call works fine locally, but fails when the app is deployed to heroku or zeit.
Here is the code:
const searchUrl = "https:/hn.algolia.com/api/v1/search?query=" + searchTerm;
axios({
method: "get",
url: searchUrl,
responseType: "json"
})
I'm making a call to Hackernews API. But when I open network tab while loading the app in heroku, I see it is making the call to https://evening-chamber-42563.herokuapp.com/hn.algolia.com/api/v1/search?query= (the actual url should be https://hn.algolia.com/api/v1/search?query=), somehow it is inserting evening-chamber-42563.herokuapp.com/ in between the actual URL that I've specified.
I thought it might be a problem with heroku, and deployed my app on zeit to see if it fixes the issue. Same thing again. This time it made a request to https://hackernews-clone-bgbmdyblch.now.sh/hn.algolia.com/api/v1/search?query= (hackernews-clone-bgbmdyblch.now.sh is where my app is deployed).
I tried with native fetch, and axios library. Still same issue.
Hours of google searching didn't help me, so I'm posting this here. Any help appreciated. Thanks.
Turns out there was a typo in the URL (missing a '/' after the protocol). It worked fine after correcting it.
When I called fetch in my localhost with the incorrect URL (missing '/'), the browser corrected it for me. But it created problems when the app was deployed on a cloud platform.

React-native android , REST api post error getting "access denied"

Developing sample application, when i was call the post method
service in componentDidMount() getting error response access
denied. Only android it's having this issue. But I got this
response IOS Devices .
I researched this case Most of the this issue get an based up on
NetWork same wife connection like emulator and my System this is
fine.
when i was check on AndroidManifest.xml file also getting
Internet Permissions also Accessed.But Still getting this Error in
Android. Please Solve this ,
Only getting in Android Device and emulator having this issue
other Platform device like IOS working fine.
Thanks in Advance.
If the REST server is on localhost in Android you'll have to use your IP instead of http://localhost.
If the rest server is not on localhost you might have to adjust the body and the headers. So instead of string body use a json object etc.
Your code:
fetch('site:ab4aca652284d7dc87ca1f347f2ac432#ori-eu-west-1.s‌​‌​earchly.co…
',{ method:'POST', headers:{ 'Accept':'application/json',
'Content-Type':'application/json' }, body:JSON.stringify(string)
}).then((response)=>response.json()).then((responseData)=>{
}).catch((err)=>{ console.error(err) })
rowDatanewOrders:{"status":"error","message":"access denied"}
make sure you have a valid json in body if you have the header 'Content-Type':'application/json', not a string as you have now!
more details about possible adjustments of the body and headers here:
https://github.com/facebook/react-native/issues/5222

PushWoosh Error : status code : 210 status_message: Invalid device token for Android

I am trying to register device token on pushwoosh services using API but it's returning me following response (Form Pushwoosh service) :
{ status_code: 210,
status_message: 'Invalid token: apa91bhosngjexchs528yuy-y4woqtkoo5b3ydddkh29etjm6eg9thg5urchcqaae32lavevq5vdco6mbyozyld4mqajg_t8-aaqnxiz6fr1gwnml7maurolpibo7-hj3at5l3i7zvzw',
response: null }
I am using Same API for iOS and it's working fine for iOS.
But the problem is with Android device. Also device token is correct (Started from "AP91...") and App is registered onGCM as well.
Thanks for help.
I got the solution and it's silly mistake I have done.
Just Uploading Answer if someone new learner get stuck, so it will helpful.
While making API call to pushwoosh registration we are sending following request in API.
"request":{
"application":"84170-XXXXX",
"push_token":deviceInfo.deviceToken,
"language":"en",
"hwid": deviceInfo.HardwareID,
"timezone": 3600,
"device_type":deviceType
}
Mistake was I missed hwid which is unique (We are using device Mac address now).
Also for Android "device_type" =3 and for ios "device_type"=1 But I earlier I was sending 1 for both (And thats the issue).
Now I am sending it according to device type. (As per given in pushwoosh docs).
and it's working fine now.
Thanks.