0
我正在使用Hapi.js作爲我們的API開發框架,並且在非常罕見的場景中出現以下錯誤。Hapi js投擲錯誤:已關閉
2015-02-08T12:32:38.073Z - verbose: err.stack > Error: Already closed
at Object.exports.create (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/node_modules/boom/lib/index.js:21:17)
at Object.exports.internal (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/node_modules/boom/lib/index.js:252:92)
at /var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/lib/request.js:297:34
at iterate (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/node_modules/items/lib/index.js:35:13)
at done (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/node_modules/items/lib/index.js:27:25)
at validate (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/lib/auth.js:283:20)
at finish (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/lib/protect.js:45:21)
at wrapped (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/node_modules/hoek/lib/index.js:798:20)
at root (/var/www/ragchewAppServerSrc/ragchew_prod/ragchews/node_modules/hapi/lib/auth.js:198:50)
at /var/www/ragchewAppServerSrc/ragchew_prod/ragchews/src/middlewares/auth/ragchew_auth_strategy.js:75:28
2015-02-08T12:32:38.073Z - verbose: err > {"isBoom":true,"output":{"statusCode":500,"payload":{"statusCode":500,"error":"Internal Server
既不能在我們的測試環境中重現此錯誤,也不知道導致此錯誤的根本原因。
如果某人突出顯示爲何/何時由框架生成此錯誤,將會非常有幫助。
在我們的代碼中,當我們嘗試從「身份驗證插件」發回答覆時發生此錯誤。我們正在使用基本認證方案。
其中問題時示例代碼段爲:
exports.register = function (plugin, options, next) {
plugin.auth.scheme('basic', function (server, options) {
var settings = options;
// some code here
var scheme = {
authenticate: function (request, reply) {
// some code here
// assign access token value to token here.
settings.validateFunc.call(request, token, function (err, isValid, credentials) {
// handle error here.
return reply(null, { credentials: credentials }); // error occurs on this line
});
}
};
return scheme;
});
next();
};
的這部分代碼看起來不錯。我認爲這個問題會在別的地方。你能否在這裏添加「一些代碼」部分? – 2015-02-09 08:58:24
其實,有很多代碼,所以我更願意知道何時拋出這個錯誤,以便我自己解決問題。 – guptakvgaurav 2015-02-09 10:48:45
你使用哪個hapi版本? – ubaltaci 2015-02-11 14:27:56