Function API only Updated 17 Oct 2026
assert(description, [resultCode])
Deprecated: prefer standard JavaScript throw new Error(...). Throws a validation error with the given message and an optional result code.
assert does not take a condition: called with one or two arguments it always throws, so put it inside an if. Use it only when you need a specific ResultCode in the JSON error response; in most cases throw new Error(...) is the better choice.
Parameters
descriptionstringrequiredMessage of the validation error.
resultCodeintoptionalCode included as ResultCode in the error response. Default is 1.
Returns
Does not return: always throws a validation error when called with one or two arguments. Called with no arguments or more than two, it does nothing.
Example
Normal JavaScript, running in the browser or on the Docly™ server.
// If request.name is null or empty string it will return
// an error 101 with specified Message and ResultCode
if (!request.name)
docly.assert("Name must be specified", 101);
// Always throw assert result, default ResultCode = 1
docly.assert("Name must be specified");
// Same as (recommended syntax):
throw new Error("Name must be specified");