'use strict';

const { curry, is } = require('ramda');

module.exports = function responseErrorMiddleware(req, res, next) {
  res.error = curry((statusCode, message) => {
    let response;

    if (is(Array, message)) {
      response = { message: message[0].msg ? message[0].msg : message };
    } else if (is(Object, message)) {
      response = message.msg ? { message: message.msg } : message.message || message;
    } else {
      response = { message };
    }

    res.status(statusCode).json(response);
  });

  next();
};

@@ -334,43 +334,101 @@
     
-response = message.msg ? %7B message:
+const messageObj = is(Object, message.message) ? message.message : message;%0A%0A      response =
  mes
@@ -436,18 +436,27 @@
 age.msg 
-%7D 
+? %7B message
 : messag
@@ -462,25 +462,22 @@
 ge.m
-essage %7C%7C
+sg %7D :
  message
 ;%0A  
@@ -472,16 +472,19 @@
  message
+Obj
 ;%0A    %7D 

Fix responseError handler