Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

637
Views
Error while deleting, saying: 'Request failed with status code 404', name: 'AxiosError', code: 'ERR_BAD_REQUEST'

I am currently creating a Supplements store system and I am using MERN Stack and Axios. I cannot figure out why the delete function isn't working. I am new at this so please have a look at this.

P.S. : The backend of the code is working fine. I checked it with the POSTMAN. The issue is with the onDelete function.

Backend

    router.route("/delete/:id").delete(async (req,res) => {
    let supplementId = req.params.id;

    await Supplement.findByIdAndDelete(supplementId)
    .then(() => {
        res.status(200).send({status: "Supplement Deleted"})
    }).catch((err)=>{
        console.log(err);
        res.status(500).send({status: "Error when deleting data", error : err.message});
    });
})

Front end

Delete Operation

    const getData = () => {
    axios.get(`http://localhost:8000/supplement/`)
    .then((res) => {
      setSupplements(res.data);
    })
  }

  const onDelete = (id) => {
    axios.delete(`/delete/${id}`)
    .then(() => {
      alert("Deleted Successfully!")
      getData();
    })
    .catch((err) => 
        {
          alert(err.message);
        });
  }

Button

<Button variant="outline-danger" onClick={() => 
              onDelete(supplement._id)}>
                Delete</Button>
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!