assert(description, [resultCode]) Last updated: 05. Aug 2026

API only function

Deprecated: Prefer standard JavaScript throw new Error(...). Throws a validation error if condition is false. Handy to use for validating arguments in an API function.

Note: This function should only be used when you need to return a specific result code. In most cases it is recommended to use throw new Error(...) instead.

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

// Same as (recommended syntax):
throw new Error("Name must be specified");