This guide outlines recommended practices for implementing the Proview SDK to ensure optimal performance, reliability, and user experience.

Error Handling

Important: When errors thrown by callback functions are not handled by the parent application, Proview will swallow these errors to prevent disruption of the SDK’s core functionality. Always implement proper error handling within your callback functions.

Callback Error Management

When implementing callback functions for session hooks or API methods, always include proper error handling:
// Good - Handle errors in callbacks
Proview.session.onSessionPause("User requested break", function (sessionStateOutput, err) {
    try {
        if (err) {
            console.error('Hook error:', err);
            return;
        }
        console.log('Session paused. Reason:', sessionStateOutput.reason);
        console.log('Session state:', sessionStateOutput.state);
        // Your custom logic here
        saveUserProgress();
        showPauseUI();
    } catch (error) {
        console.error('Error in pause handler:', error);
        // Handle the error appropriately
    }
});

// Bad - Unhandled errors
Proview.session.onSessionPause("User requested break", function (sessionStateOutput, err) {
    // If this throws an error, Proview will swallow it
    riskyOperation(); // Could throw an error
});

Global Error Handler

Register a global error handler to catch SDK-level errors:
Proview.onError((err) => {
    console.error('Proview SDK Error:', err);

    // Log to your monitoring system
    if (err.type === 'critical') {
        logCriticalError(err);
    }

    // Show user-friendly message for critical errors
    if (err.type === 'critical') {
        showUserNotification('A technical issue occurred. Please contact support.');
    }
});