D
D
deadkEEper12015-12-09 20:34:39
Node.js
deadkEEper1, 2015-12-09 20:34:39

How to correctly render errors on node js with Backbone?

And so, my example.
Trying to render a model/collection using fetch

var usersCollection = new UsersCollection
        usersCollection.fetch({
          success: function(data, res, options){
            console.log('Res is ' ,  res)
          }
          ,

          error: function(data, res, options){
            console.log('Error ', res )
          }		
        })

get request for urls works fine. Here I deliberately create an error object and send it to the middleware handler
usersRouter.route('/')
  .get(function(req, res, next) {

    var err = new Error(
      this.message = 'Some error')
    next(err)
})

The handler gets an error (because it outputs to the console)
app.use(function(err, req, res, next){
  console.log( err)
  
  // res.send(err)
  res.render('ErrorView', err)
  
})

but if I try to render an error, instead of rendering, the error callback function of the fetch method fires.
error: function(data, res, options){
            console.log('Error ', res )
          }

Template engine setting comes before middleware
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

What am I doing wrong? Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question