0

I have the following Restify route handler defined.

MyModule.prototype.uploadDateChecker = function (req, res, next) {
    req.locals = {};
    var handlerConfig = req._self = this;

    //Uncommenting this line does throw the exception with the message.
    //next(new Error("Test Error"));

    var continueProcessing = commonUtils.processInputs(req, res, next, handlerConfig, __function, __line);
    ...
    //If I uncomment this one instead, some other exception is thrown first somewhere resulting in: {"code":"InternalError","message":""}
    //next(new Error("Test Error: "+continueProcessing));

For some reason, after the commonUtils.processInputs function returns, the client receives a 500 error with a message of "". If I add a

next(new Error("Test Error"));

right before the call to processInputs, then the 500 error has a "Test Error" in the body. If I move it to right after the processInputs, then the 500 has no message. Apparently another exception is being thrown from inside processInputs with any message. However, if I go into that processInputs and right before the return I add that next(new Error("Test Error")) statement, then the client gets the Test Error. So I don't know how/why the blank message is being thrown when the throw lines are commented out.

End of ProcessInputs:

...
commonUtils.processOutputs = function (req, res, next, handlerConfig, func, line) {
    var resp = commonUtils.enterExit(req, res, next, handlerConfig, func, line, "START");
    //Uncommenting this line results in: {"message":"Test Error: true"}
    //next(new Error("Test Error: "+resp));

    return resp;

}

HTTP Response Body without the message:

{"code":"InternalError","message":""}

HTTP Response Body with the message (inside processInputs):

{"message":"Test Error: true"}
user994165
  • 9,146
  • 30
  • 98
  • 165

1 Answers1

0

It turns out that inside of commonUtils.processInputs I was calling eval, which threw an error and I immediately caught. I then called next(err.message+"some other text") instead of next(new Error(errmessage+"some other text")); Since "next(err)" expects err to be an Error object, a new Error due to the syntax error was thrown.

user994165
  • 9,146
  • 30
  • 98
  • 165