3 var normalizeRedirect = require('./normalise-redirect');
4 var StatusError = require('statuserror');
7 * Handles various 404 and 301 error codes and deals with the
8 * in a reasonable manner
10 function redirectErrorMiddleware(err, req, res, next) {
13 // TODO: check this works for userhome....
15 res.redirect(normalizeRedirect(err.path, req));
16 // Terminate processing
20 return next(new StatusError(500, 'Invalid redirect'));
23 if (err.githubType === 'ORG' && err.uri) {
24 var url = '/orgs/' + err.uri + '/rooms';
25 //test if we are trying to load the org page in the chat frame.
26 //fixes: https://github.com/troupe/gitter-webapp/issues/628
27 if (/~chat$/.test(req.route.path)) {
28 url = url += '/~iframe';
32 // Terminate processing
40 module.exports = redirectErrorMiddleware;