2016-10-06 64 views
0

我有以下Restify定义的路由处理程序。确定异常被神秘抛出

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)); 

出于某种原因,经过commonUtils.processInputs函数返回时,客户机接收具有“”的消息的500错误。如果我在调用processInputs之前添加一个

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

,那么500错误在主体中有一个“测试错误”。如果我将它移动到processInputs之后,那么500没有消息。显然,另一个异常是从processInputs中引发任何消息。但是,如果我进入该processInputs并在返回之前,我添加下一个(新的错误(“测试错误”))语句,然后客户端得到测试错误。所以我不知道当抛出线被注释掉时如何/为什么会抛出空白消息。

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响应身体没有消息:

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

HTTP响应体与所述消息(内侧processInputs):

{"message":"Test Error: true"} 
+0

没有一个看起来很喜欢。你确定这是关于调整吗? – HeadCode

+0

@Head Coder,都是我的Restify路由器处理程序使用的所有帮助程序函数,并且我通过了req,res和next。 – user994165

回答

0

原来那commonUtils.processInputs里面我正在调用eval,它立即抛出一个错误 抓住。然后,我接着调用下一个(err.message +“一些其他文本”),而不是下一个(新错误(errmessage +“其他文本”));由于“next(err)”期望err是一个Error对象,所以会引发由于语法错误而导致的新错误。