assert(description, [resultCode]) Last updated: 17. Oct 2026

API only function

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.

See also: isNotNull isString isNumber isEmail

Parameters

Name Type Description
description string

Message of the validation error.

resultCode (optional) int

Code 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

Code example (JS)

JS is normal JavaScript either 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");