assert(description, [resultCode]) Last updated: 30. May 2026

API only function

Throws a validation error if condition is false. Handy to use for validating arguments in an API function.

See also: isNotNull isString isNumber isEmail

Parameters

Name Type Description
description string

Text to throw as exception if condition is evaluated as "false".

resultCode (optional) int

Code to include in the result JSON.

Returns

Throws a validation exception with description as text if condition evaluates to false.

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");