Home > Net >  AxiosError {message: 'Request failed with status code 500', name: 'AxiosError',
AxiosError {message: 'Request failed with status code 500', name: 'AxiosError',

Time:09-20

I am learning React and Redux and came up with this error. I am not sure what is driving this error. I do know it is in CartActions.js and pretty sure it has to do with my local storage but not sure. Can someone please steer me in the right direction? Maybe explain this error and how to fix it?

cartActions.js

import axios from 'axios'
import {
    CART_ADD_ITEM,
    CART_REMOVE_ITEM,
    CART_SAVE_SHIPPING_ADDRESS,

    CART_SAVE_PAYMENT_METHOD,
} from '../constants/cartConstants'


export const addToCart = (id, qty) => async (dispatch, getState) => {
    const {data} = await axios.get(`/api/products/${id}/`)
    dispatch({
        type: CART_ADD_ITEM,
        payload: {
            product: data._id,
            name: data.name,
            image: data.image,
            price: data.price,
            countInStock: data.countInStock,
            qty
        }
    })
    localStorage.setItem('cartItems', JSON.stringify(getState().cart.cartItems))
}



// export const removeFromCart = (id) => (dispatch, getState) => {
//     dispatch({
//         type: CART_REMOVE_ITEM,
//         payload: id,
//     })

//     localStorage.setItem('cartItems', JSON.stringify(getState().cart.cartItems))
// }


// export const saveShippingAddress = (data) => (dispatch) => {
//     dispatch({
//         type: CART_SAVE_SHIPPING_ADDRESS,
//         payload: data,
//     })

//     localStorage.setItem('shippingAddress', JSON.stringify(data))
// }

// export const savePaymentMethod = (data) => (dispatch) => {
//     dispatch({
//         type: CART_SAVE_PAYMENT_METHOD,
//         payload: data,
//     })

//     localStorage.setItem('paymentMethod', JSON.stringify(data))
// }

CodePudding user response:

When you face an error with a status code in the 500 range, it is related to the bad response, either you're server is offline, or it could be anything. Can you check that the issue is not with the backend?

CodePudding user response:

Let me say it in few words :) 400 code - your bad (request is bad) 500 code - server bad (tell the BE guy)

  • Related