I've tried every solution to the problen mentioned in this StackOverflow Question, neither this one
It seems the Post Owner of that first link couldn't find a solution, so I'm reposting (not 100% a repost) the question.
My Axios setup is as simple as it can be:
const baseURL = 'https://react-course-rn-cafe.herokuapp.com';const cafeApi = axios.create({ url: baseURL +'/api',});// signIn request method const signIn = async (email: string, password: string) => { try { const resp = await cafeApi.post<LoginResponse>('/auth/login', { correo: email, password, }); console.log(resp.data); } catch (error) { console.log(error)
that URL is the gateway to my BackEnd deployed in heroku, I know its not a server side problem because i've also run it in a local environment and it's the same result. Besides, in both cases i can send requests through Postman and it works perfectly fine.
I've noticed axios is not "waiting" for the server response, the error logs instanly after i press the button, (postman takes 300ms-2000ms)
this is the error:
[AxiosError: Network Error]
I've tried catching the error as specified in the Axios website's documentation, like this:
catch (error) { if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx console.log('error.data: '+ error.response.data); console.log('error.status: '+ error.response.status); console.log('error.headers:'+ error.response.headers); } else if (error.request) { // The request was made but no response was received // `error.request` is an instance of XMLHttpRequest in the browser and an instance of // http.ClientRequest in node.js console.log(error.request); } else { // Something happened in setting up the request that triggered an Error console.log('Error', error.message); } console.log('error.config: '); console.log(error.config); }
this is the error log:
error.data: undefinederror.status: 0error.headers:undefinederror.config:{"adapter": [Function xhrAdapter], "data": "{}", "env": {"FormData": null},"headers": {"Accept": "application/json, text/plain, */*", "Content-Type": "application/json"}, "maxBodyLength": -1, "maxContentLength": -1, "method": "post", "timeout": 0, "transformRequest": [[Function transformRequest]], "transformResponse": [[Function transformResponse]],"transitional": {"clarifyTimeoutError": false, "forcedJSONParsing": true, "silentJSONParsing": true},"url": "/auth/login","validateStatus": [Function validateStatus],"xsrfCookieName": "XSRF-TOKEN", "xsrfHeaderName": "X-XSRF-TOKEN"}
If i check my server side logs i can see the response sent has a status of 200, or 400 (depending the parameters i sent), but the received response is 0.
I know this is not CORS, it's enabled on server side.
Please help!!! I've been stuck for a whole day now.