Assert(description, [resultCode]) Last updated: 15. Mar 2023
API only function
Throws a validation error if condition is false. Handy to use for validating arguments in an API function.
Parameters
Name | Type | Description |
---|---|---|
description | string | Text to throw as excepion if condition is evaled as "false". |
resultCode (optional) | int | Code to include in the result JSON. |
Returns
Throws a validation exception with description as text if condition evals 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 403 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");