Closed lexfernandez closed 8 years ago
@lexfernandez This isn't an issue related to the middleware ("Network request failed"), but with the request. Considering this is outside the scope of this project, I won't be able to provide any help for you, sorry.
I would suggest, however, catching the error and taking a look at your response. The Fetch API returns a promise, so you can do this:
export function login(username,password) {
return {
type: actions.LOGIN,
payload: {
promise: fetch(environment.serverURL+'/Users/login', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
'username': username,
'password': password
})
}).then(...).catch(...)
}
}
}
Thanks @pburtchaell , I alredy solved it, the problem was in my api.
hi @lexfernandez , I have the same issue you already solved. Please let me know what I have to revise in the api? The api is developed in php.
Hi @NicklassFransson, you will need to add the then and catch statements in order to see whats the problem on your api.
You will need something like this:
export function login(username,password) {
return {
type: actions.LOGIN,
payload: {
promise: fetch(environment.serverURL+'/Users/login', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
'username': username,
'password': password
})
}).then(function(response) {
return response.json()
}).catch(function(err) {
return err;
})
}
}
}
one you catch the error you will be able to see if the problem is with your api or if your request correctly.
You can download my example from my repo GoGreen and the api from GoGreenApi
Thank you, @lexfernandez . I've also found the reason and resolved. Thanks a lot.
Thank you, @lexfernandez . let me know what changes u made and how you resolved..
@ghost . I'm also experiencing the same issue plz let me know how to resolved. Thanks a lot.
Hi @abuammar, as @pburtchaell said, it is not a problem with the middleware but a problem related to the request you made, there could be many reasons but you can find out what is you problem if you catch the error.
Hi @NicklassFransson, you will need to add the then and catch statements in order to see whats the problem on your api.
You will need something like this:
export function login(username,password) { return { type: actions.LOGIN, payload: { promise: fetch(environment.serverURL+'/Users/login', { method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ 'username': username, 'password': password }) }).then(function(response) { return response.json() }).catch(function(err) { return err; }) } } }
one you catch the error you will be able to see if the problem is with your api or if your request correctly.
You can download my example from my repo GoGreen and the api from GoGreenApi
Hi guys,
I am trying to make a request to my restfull api but for some reason I always get [PREFIX]_REJECTED as response and there is only this warning telling me there is a possible unhandled promise rejection.
Warning: Possible Unhandled Promise Rejection (id: 0): Network request failed TypeError: Network request failed at XMLHttpRequest.xhr.onerror (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:30143:8) at XMLHttpRequest.dispatchEvent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:13221:15) at XMLHttpRequest.setReadyState (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:29599:6) at XMLHttpRequest._didCompleteResponse (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:29481:6) at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:29430:51 at EventEmitter.emit (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:12818:23) at MessageQueue.__callFunction (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:11253:23) at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:11157:8 at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:11111:1) at MessageQueue.callFunctionReturnFlushedQueue (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:11156:1)
This is my code:
authReducer.js