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

285
Views
Nodejs - error message, n-th failure outputs n number of failure messages

I would like to ask you a question about the error message of the Node.Js.

Specifically, it is a question about the number of printed messages.

In my server.js, I made some situation for send status 400. Then list.ejs receives information about the server status, then print message list.ejs - fail for deleting in console.

But the number of messages printed is different for each failure. The first failure outputs one message and the second failure outputs two messages, n-th failure outputs n messages. ( You can watch below gif what happens in my code ).

Please tell me why it is like this.

I wrote the code as below.

  • server.js
app.delete('/delete', (req, res) => {
  // console.log(req.body);
  req.body._id = parseInt(req.body._id);
  var deleteObj = {_id: req.body._id, writer: req.user._id};
  // var deleteObj = {_id: req.body._id};
  db.collection('post').deleteOne(deleteObj, (errDeleteOne, resDeleteOne) => {
    if (errDeleteOne) {
      res.status(400).send({message: 'server.js - error in deleting'});
      return console.log(errDeleteOne);
    }
    if (resDeleteOne.deletedCount == 0) {
      res.status(400).send({message: 'server.js - not have permission to delete'});
      return console.log('server.js - console.log - not have permission to delete');
    }
    console.log('server.js - console.log - success for deleting');
    console.log(resDeleteOne);
    res.status(200).send({message: 'server.js - success for deleting'});
  });
});
  • list.ejs
    <script>
      $('.delete').click((event) => {
        var clickedId = event.target.dataset.id;
        var clickedItem = event.target;
        document.querySelector('.modal').style.display = 'block';

        $('.btn-close').click((event) => {
          document.querySelector('.modal').style.display = 'none';
        })
        
        $('.btn-confirm').click((event) => {
          $.ajax({
            method : 'DELETE',
            url: '/delete', // 요청할 경로
            data: {_id : clickedId} // 요청과 함께 보낼 데이터
          }).done((res) => {
            document.querySelector('.modal').style.display = 'none';
            console.log('list.ejs - success for deleting');
            $(clickedItem).parent('li').fadeOut();
          }).fail((xhr, code, err) => {
            document.querySelector('.modal').style.display = 'none';
            console.log('list.ejs - fail for deleting')
          })
        })
      })
    </script>

[implementation gif]

about 4 years ago · Juan Pablo Isaza
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!