You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to return a json object but there is no response data coming back. It works fine over postman but not when using axios. Can someone help me with this?
My frontend code looks like this:-
exportconstgetCollaborator = (collaboratorID, dispatch) => {
axios
.get(`http://localhost:8081/collaborators/${collaboratorID}`,
{
headers:{
"Accept": "application/json"
}
})
.then(
// success
({ data, status }) => {
console.log("status", status);
returndispatch({
type: GET_COLLABORATOR,
payload: data
});
}
).catch(error => {
if (error.response) {
// The request was made and the server responded with a status code// that falls out of the range of 2xxconsole.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} elseif (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.jsconsole.log(error.request);
} else {
// Something happened in setting up the request that triggered an Errorconsole.log('Error', error.message);
}
console.log('====================================');
console.log(error);
console.log('====================================');
console.log(error.config);
});
};
And the mock file:-
HTTP/1.1 200 OK
Content-Type: application/json
#import './data.json';
I'll try and reproduce it and send the error log. I have tried the same call using json-server and it works fine. Very odd. Not sure what I am doing wrong. Would be grateful if someone could try and reproduce in case it is my environment that is causing an issue.
It was returning Network Error with no status code. It goes straight here:-
.catch(error => {
if (error.response) {
// The request was made and the server responded with a status code// that falls out of the range of 2xxconsole.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} elseif (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.jsconsole.log(error.request);
} else {
// Something happened in setting up the request that triggered an Errorconsole.log('Error', error.message);/* <-- code executes here */
}
console.log('====================================');
console.log(error);
console.log('====================================');
console.log(error.config);
});
I'm trying to return a json object but there is no response data coming back. It works fine over postman but not when using axios. Can someone help me with this?
My frontend code looks like this:-
And the mock file:-
data.json:-
The text was updated successfully, but these errors were encountered: