Uncaught (in promise) Error: Request failed with status code 404
Solution 1
Generally this error comes when the url/location provided inside GET method is not correct. So check the url/location again and correct it.
So most probably there is some mistake here : '/api/current_user'
Solution 2
In my case it was a minor syntax error (a misplacement of my brackets). My code looked like this:
axiosget("/api-url").then(
(response) => {
doSomething();
}), () => {
doError();
}
);
instead of this:
axiosget("/api-url").then(
(response) => {
doSomething();
}, () => {
doError();
});
);
If you get this error message it means that your error handling-code isn't there or that it could not be reached, therefore the promise was unhandled (since the catch-part of your wasn't properly setup).
If you get this message always doublecheck your syntax!
Ishan Patel
I write React, TypeScript, JavaScript, CSS, HTML and sometimes Ruby.
Updated on July 04, 2021Comments
-
Ishan Patel almost 3 years
I am getting above error while fetching some data from the API. Following is the code of the
action creator
where I am tryingGET
the data:import { FETCH_USER } from './types'; import axios from 'axios'; export const fetchUser = () => async dispatch => { console.log('fetchUser'); const res= await axios.get('/api/current_user'); dispatch({ type: FETCH_USER, payload: res }); };
Also when I am debugging in the code editor, console is giving me below error:
SyntaxError: Unexpected token import