Reputation: 178
In MarkLogic 9, I'm using a custom SJS service with POST method where I do some basic search & validation giving a custom result for errors (Not using fn.error because of requirements).
The error that I return in POSTMAN is a simple JSON like this:
{
"code":400,
"message":"Bad request",
"reason":"string"
}
The HTTP code-message header above the response in POSTMAN shows "200 OK" even after using xdmp.setResponseCode(400, "Bad request");
How to set the HTTP code to a manual number/message while following the standard protocols?
Upvotes: 0
Views: 155
Reputation: 7335
It depends whether the custom SJS service is
a Data Service endpoint
Set the errorDetail property in the *.api declaration and throw the error mapped to the HTTP status code (see https://docs.marklogic.com/guide/java/DataServices#id_74238).
a REST API resource service extension
For a 2xx status, set the outputStatus
property on
the context
parameter object (see
https://docs.marklogic.com/guide/rest-dev/extensions#id_26045).
For a 4xx status, throw a RESTAPI-SRVEXERR
error (see
https://docs.marklogic.com/guide/rest-dev/extensions#id_20992).
an HTTP endpoint module
Call the xdmp.setResponseCode()
function (see https://docs.marklogic.com/xdmp.setResponseCode)
Hoping that helps,
Upvotes: 2