Search code examples
javascriptreactjsasync-awaites6-promise

uncaught error in js promise in react/redux app


I am trying to get some data using this code

import mainAPI from '../api'

export const sendActions = () => async dispatch => {
    const response = await  mainAPI.get('/posts')
    dispatch({ type : "FETCH_POSTS",payload :response }) 
}

I am getting below error message in the console

createError.js:17 Uncaught (in promise) Error: Request failed with
status code 404
at createError (createError.js:17)
at settle (settle.js:19) . at XMLHttpRequest.handleLoad (xhr.js:60) this is my api code

import axios from 'axios'
export default axios.create({mainAPI: 'https://jsonplaceholder.typicode.com'})

If anyone knows tell me how to resolve


Solution

  • I should have added baseURL, I have added a diffrent name thats why it was showing localhost

    import axios from 'axios'
    export default axios.create({baseURL: 'https://jsonplaceholder.typicode.com'})