For the complete documentation index, see llms.txt. This page is also available as Markdown.

Throwing business exceptions

If business logic validation (e.g., missing appropriate roles, incorrect parameters) fails, the script should stop processing the request and present the user with a clear error message. This is done using the business exception mechanism.

Throwing an error requires using the error page definition builder (getErrorPageDefinitionBuilder), which allows you to specify the appropriate Content artifact template (TextContent) and inject the error description.

Detailed rules for creating and configuring error pages are described in the chapter: Error pages.

Example of throwing an exception

The function below presents the standard pattern for raising a business error inside a script callService.

function callService(context) {
    const isConditionMet = false; // Example validation result
    
    if (!isConditionMet) {
        // Stop the script and display the error page
        throwBusinessError("error_page_default-*", "No appropriate role to start the process.");
    }
    
    return [{'status': 'success'}];
    
    // Helper function for generating business exceptions.
    function throwBusinessError(textcontentName, errorDescription) {
        const builder = context.getErrorPageDefinitionBuilder();
        builder.bodyTextContent(textcontentName);
        builder.msg(errorDescription);
        
        // Throwing the exception stops further script processing
        context.throwBusinessException(builder);
    }
}

Last updated

Was this helpful?