const path = require('path');
const paramsProc = require('n-params-processor');
const config = require('../config/environment');
const logger = require('./_common/util/logger');

module.exports = (app) => {
  require('./users/routes')(app);

  app.get('*', (req, res) => {
    let indexPage = path.join(config.get('publicPath'), 'index.html');
    res.sendFile(indexPage);
  });

  // eslint-disable-next-line no-unused-vars, max-params
  app.use((err, req, res, next) => {
    if (err instanceof paramsProc.ParamsProcessorError) {
      return res.status(422).send({ reason: err.message });
    }
    if (err.statusCode < 500) {
      return res.status(err.statusCode).send({
        reason: err.message,
        info: err.info
      });
    }

    // istanbul ignore next
    switch (process.env.NODE_ENV) {
      case 'test':
      case 'development':
        logger.error('Unexpected server error', err, err.stack);
        break;
      case 'production':
        logger.error('Unexpected server error', err);
        break;
    }

    err = new Error('Unexpected server error');
    res.status(err.statusCode || 500).send({ reason: 'Unexpected server error' });
  });
};

@@ -561,22 +561,23 @@
 .send(%7B 
-reason
+message
 : err.me
@@ -679,22 +679,23 @@
         
-reason
+message
 : err.me
@@ -1128,14 +1128,15 @@
 d(%7B 
-reason
+message
 : 'U

return error.message instead of error.reason