我有以下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"}
沒有一個看起來很喜歡。你確定這是關於調整嗎? – HeadCode
@Head Coder,都是我的Restify路由器處理程序使用的所有幫助程序函數,並且我通過了req,res和next。 – user994165