express - Node.js delete request -


I have a node. Js application that has Express for express and Mongoose for database access.

I is an HTTP delete request that is deleting an entry in the database if some of the requirements are met.

  .delete (function (rick, rays) {Movie.findOne ({_ id: req.params id}, function (mistake, movie) {if (err) res.send (err) ); For (var i = 0, len = movie.actors.length; i & lt; len; i ++) {if (movie.actors [I] .actor == "Chuck Norris") {res.status ( 403) .Send ({Message: 'Can not remove Chuck Norris}');} And (Movie Removes ({_ id: req.params.id}, Function (mistake, movie) {if (err) res .send (err); res.json ({message: 'movie deleted'})}}}}}}})}}  

If I have a movie with a Send HTTP delete, check in the list of actors if Chuck Norris is in the movie and I will be removed from there I can. / P>

The problem is that my console is returning me this error:

  error: can not set the header after sending  

So I think this is an issue with my callback. "Slow" database call was created due to the asynchronous nature of the node.JS, that my delil has sent a header already before ?

Before deleting I can manage validation and proper HTTP error I Od send If deletion is not possible?

When you respond to the request several times in the same radius, be careful as it is. On the error you should fill out the return to res.send (err) so that the execution will not continue. The same goes for for-loop in your res.status () .


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -