如何在 MarkLogic REST 函数中设置自定义 HTTP 代码

How to set custom HTTP code in MarkLogic REST function

在 MarkLogic 9 中,我使用带有 POST 方法的自定义 SJS 服务,我在其中进行一些基本搜索和验证,为错误提供自定义结果(由于要求,未使用 fn.error) .

我在 POSTMAN 中 return 的错误是一个简单的 JSON 像这样:

{
"code":400,
"message":"Bad request",
"reason":"string"
}

即使在使用 xdmp.setResponseCode(400, "Bad request");

后,POSTMAN 中响应上方的 HTTP code-message header 仍显示“200 OK”

如何在遵循标准协议的同时将 HTTP 代码设置为手动 number/message?

取决于自定义SJS服务是否

希望对您有所帮助,