2016-10-06 7 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レスポンスボディメッセージなし:(processInputs内部の)メッセージと

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

HTTPレスポンスボディ:

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

これはどれも非常に似ていないようです。これが修復についての確信ですか? – HeadCode

+0

@Head Coderは、すべて私のRestifyルータハンドラで使用されるヘルパー関数であり、req、res、およびnextで渡されました。 – user994165

答えて

0

は、それが判明commonUtils.processInputsの中で私はエラーを投げたevalを呼び出していました。すぐに捕らえられた私は次の(新しいエラー(errmessage + "他のテキスト"))の代わりにnext(err.message + "some other text")を呼び出しました。 "next(err)"はerrがErrorオブジェクトであることを期待しているので、構文エラーによる新しいErrorがスローされました。

関連する問題