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"}