I am building an app with angularjs using ui-router and my API is handled by an express server with nodejs.
I'm trying to handle properly the server errors such as 404 and 500 errors. The way I do it know is the following:
// handling 404 errors
app.use(function(err, req, res, next) {
if (err.status !== 404)
return next(err);
res.status(404)
res.render('index', { status: '404' })
});
And then I catch the route on the server side with ui-router:
$urlRouterProvider.otherwise('/error');
This works fine for 404 and I do the same for 500 error. The only problem is that I don't know how to get the error status code.
On can I catch the status sent by the server with ui-router or without making an extra http request?