ValidationError:“值”必须是一个对象-ResponseValidation阶段

问题描述

使用hapi服务器,我从这样的处理程序中返回:

async function handler (req,h) {
  ...
  h.unstate(key,cookieOptions);
  const resp = h.redirect(redirectUri);
  return resp;
}

...但返回HTTP 500错误。我在堆栈跟踪中找到了失败:

ValidationError: "value" must be an object
    at Object.exports.process (~/project/node_modules/hapi/node_modules/joi/lib/errors.js:201:19)
    at internals.Object._validateWithOptions (~/project/node_modules/hapi/node_modules/joi/lib/types/any/index.js:751:31)
    at module.exports.internals.Any.root.validate (~/project/node_modules/hapi/node_modules/joi/lib/index.js:146:23)
    at exports.response (~/project/node_modules/hapi/lib/validation.js:173:31)
    at Request._postCycle (~/project/node_modules/hapi/lib/request.js:356:68)
    at Request._reply (~/project/node_modules/hapi/lib/request.js:335:20)
    at Request._execute (~/project/node_modules/hapi/lib/request.js:171:14)
    at processticksAndRejections (internal/process/task_queues.js:97:5)

...似乎来自响应验证生命周期,位于 onPostHandler onPreResponse 之间。

可能是什么问题?

解决方法

失败来自重定向时未初始化的响应,首先创建空响应应将其修复:

async function handler (req,h) {
  ...
  const resp = h.response().redirect(redirectUri);
  return resp;
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...