TronDesigner – Integration Examples
Docs: Developer documentation  |  Debugging and error handling  |  Events and callbacks

Back to examples

Error Handling

The integration script reports most problems in the browser console instead of throwing. Where your code can react:

Close the editor's error dialog to see the onClose result in the log below. Add data-td-log-level="debug" to the script tag for detailed console output while you develop.

Oregon 400 ml - Red

Invalid Product Code

Editor shows No products found; closing it logs onClose('Error').
Oregon 400 ml - Red

Invalid Print Configuration

Editor shows Selected print options not found; closing it logs onClose('Error').
Oregon 400 ml - Red

Invalid Print Job GUID

Editor shows Print job ... not found; closing it logs onClose('Error').

Invalid Custom Button

setEditorButtons() throws synchronously - caught with try/catch, the editor doesn't open.

Rejected API Call

getPrintJob() with an unknown GUID - the promise rejects, caught with try/catch.

Result Log

Error Handling Patterns

1. Wait for initialization

try {
    await window.tronDesigner.getInitializing();   // rejects when initialization failed
} catch (error) {
    console.error('Designer not available:', error.cause ?? error.message);
}

// or, right before opening:
if (!window.tronDesigner?.getInitialized()) {
    showError('The designer is not available right now.');
}

2. React to editor errors with onClose

// openDesigner() returns nothing - don't chain .then() / .catch()
window.tronDesigner.openDesigner(editorArguments, {
    mode: 'dialog',
    onClose: (reason) => {
        // 'Confirmed' | 'Cancelled' | 'Error'
        if (reason === 'Error') showError('The designer could not be loaded. Please contact us.');
    }
});

3. Synchronous validation errors

try {
    window.tronDesigner
        .setEditorButtons(buttonsFromConfig)   // throws on invalid buttons - call it first
        .setExactProduct('PFC', undefined, (b) => b.addVariant('10086021'))
        .addExactPrinting('front', 'PAD03')
        .open({ mode: 'dialog', onClose });
} catch (error) {
    console.error('Could not open the designer', error);
}

4. API calls

try {
    const printJob = await window.tronDesigner.getPrintJob(printJobGuid);
} catch (error) {
    console.error('Print job could not be loaded', error.message, error.cause);
}