Error Handling
Collaboration-Specific Errors
Handle collaboration failures gracefully:Copy
handleCollaborationError(event) {
const { eventMessage, type } = event;
switch (type) {
case 'NOTIFICATION_MULTI_ASSISTANT_COLLABORATION_FAILED':
console.error('Collaboration failed:', eventMessage.content);
this.showUserError('Collaboration could not be completed. Please try again.');
break;
case 'ERROR_INVALID_COLLABORATION_REQUEST':
console.error('Invalid collaboration request:', eventMessage.content);
this.showUserError('Invalid collaboration request. Please check agent handles.');
break;
default:
// Handle other collaboration errors
console.error('Collaboration error:', eventMessage.content);
this.showUserError('An error occurred during collaboration.');
}
}
showUserError(message) {
// Show error to user in your UI
document.dispatchEvent(new CustomEvent('collaboration_error', {
detail: { message }
}));
}
Connection Management
Build upon existing SSE connection management for collaboration:Copy
class RobustCollaborationClient extends EnhancedSSEClient {
constructor(threadId, apiKey, userId) {
super(threadId, apiKey, userId);
this.reconnectAttempts = 0;
this.maxReconnectAttempts = 3;
}
setupEventSource() {
super.setupEventSource();
this.eventSource.onerror = (error) => {
console.error('SSE connection error:', error);
if (this.reconnectAttempts < this.maxReconnectAttempts) {
this.reconnectAttempts++;
setTimeout(() => {
console.log(`Reconnecting... Attempt ${this.reconnectAttempts}`);
this.setupEventSource();
}, 1000 * this.reconnectAttempts);
} else {
this.showUserError('Connection lost. Please refresh the page.');
}
};
this.eventSource.onopen = () => {
console.log('SSE connection established');
this.reconnectAttempts = 0;
};
}
}