Error handling for Ajax request in express.js

Viewed 1597

I can't seem to find out how to print a custom error message in alert().

I found this in the express guide

app.use(function(err, req, res, next){

if (req.xhr) {
    res.send(500, {error: 'Oops'});
} else {
    next(err);
}

});

I got only to print the error code like this:

request.fail(function(jqXHR, textStatus, err) {
    alert(err);
});

But how to i print 'Oops' or any other message that bubbles up to my custom middleware?

Thanks in advance

1 Answers
Related