Home > widget-integration > RecommendationAnalytic > handleStorageError
RecommendationAnalytic.handleStorageError() method
Handles errors that occur when storing recommendation tracking data to localStorage.
This method is called when localStorage operations fail, providing an extension point for custom error handling strategies. Common failure scenarios include storage quota exceeded, private browsing mode restrictions, or localStorage being disabled.
Override this method to implement shop-specific error handling, fallback storage mechanisms, or integration with error tracking services.
Signature:
protected handleStorageError(error: Error, data: RecommendationWidgetTrackingData): void;
Parameters
| 
 Parameter  | 
 Type  | 
 Description  | 
|---|---|---|
| 
 error  | 
 Error  | 
 The error that occurred during the storage operation. Common error types include QuotaExceededError (storage full) and SecurityError (private mode).  | 
| 
 data  | 
 The recommendation widget tracking data that failed to store. This data can be used for retry attempts or alternative storage strategies.  | 
Returns:
void
Remarks
Common localStorage errors and their causes: - **QuotaExceededError**: Storage limit reached (typically 5-10MB per domain) - **SecurityError**: localStorage disabled in private/incognito mode - **InvalidStateError**: localStorage is being accessed before it's ready
The default implementation logs errors to console. In production environments, consider implementing more robust error handling strategies.
Example 1
Override to implement fallback to sessionStorage:
protected handleStorageError(error: Error, data: RecommendationWidgetTrackingData): void {
  console.warn('localStorage failed, trying sessionStorage:', error.message);
  try {
    const key = this.generateStorageKey(data.wid);
    sessionStorage.setItem(key, JSON.stringify(data));
  } catch (fallbackError) {
    console.error('All storage methods failed:', fallbackError);
  }
}
Example 2
Override to send failed data to analytics API:
protected handleStorageError(error: Error, data: RecommendationWidgetTrackingData): void {
  // Log error to monitoring service
  if (window.Sentry) {
    window.Sentry.captureException(error, {
      extra: { trackingData: data }
    });
  }
  // Send data directly to analytics endpoint as fallback
  fetch('/api/track-recommendation', {
    method: 'POST',
    body: JSON.stringify(data),
    headers: { 'Content-Type': 'application/json' }
  }).catch(apiError => {
    console.error('Analytics API fallback failed:', apiError);
  });
}