繁体   English   中英

重整异常被神秘抛出

[英]Restify exception being mysteriously thrown

我定义了以下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错误,消息为“”。 如果我添加一个

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

在调用processInputs之前,则500错误的主体中包含“测试错误”。 如果我在processInputs之后将其移到右边,则500没有消息。 显然,任何消息都会从processInputs内部引发另一个异常。 但是,如果我进入那个processInputs,并且在返回之前就添加了next(new Error(“ Test Error”))语句,那么客户端将得到Test Error。 所以我不知道注释行时抛出空白消息的原因/原因。

流程输入结束:

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

原来,在commonUtils.processInputs内部,我正在调用eval,这引发了错误,我立即被抓住。 然后,我调用了next(err.message +“其他文本”)而不是next(new Error(errmessage +“其他文本”)); 由于“ next(err)”期望err是一个Error对象,因此由于语法错误而引发了一个新的Error。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM