Search code examples
reactjshttpreduxredux-saga

Post request in redux-saga not working, nothing seems to happen


I would like to make post request in redux-saga. My code looks like:

var formdata = new FormData();
    formdata.append("points", "a,b");
    formdata.append("pid", "someid");
    formdata.append("tions", "cses");
    formdata.append("exp", "cx");
const ans = yield call(fetch,
'http://localhost:8000/api',
{
    method: "POST",
    headers: { 'Authorization': 'Token tokenid',
                "Content-Type": "application/json",},
    body : formdata
});

In Postman it is working fine (selected form-data in body), but in saga, the POST request is not happening at all.

Please suggest where I am doing wrong?


Solution

  • The problem is with your Exceptions on server-side, When you are throwing an error the headers are not set. So what you should do is with CORS Errors only with 400 bad request react fetch request.