'Can not get the catch error using axios in functional component in react 18

Axios version 0.27.2 Can not get the catch error using axios in functional component in react 18

 axios.delete(`http://localhost:4000/stock/${id}`)
            .then(data => {
                if(data.data.deletedCount > 0) {
                    const remaining = products.filter(product => product._id !== id)
                    setProducts(remaining)
                    toast.success('Item Deleted Successfully')
                }
            })
        .catch(error=>{
            console.log(error);
        })


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source