* Handle upload errors with fallback to local download * @param {Array} trackingLog - Array of recorded actions * @param {number} popupWindowId - ID of the processing popup window * @param {Error} error - The error that occurred
(trackingLog, popupWindowId, error)
| 152 | * @param {Error} error - The error that occurred |
| 153 | */ |
| 154 | async function handleUploadError(trackingLog, popupWindowId, error) { |
| 155 | // Close popup if it exists |
| 156 | if (popupWindowId) { |
| 157 | chrome.windows.remove(popupWindowId).catch(() => { |
| 158 | // Window might already be closed |
| 159 | }); |
| 160 | } |
| 161 | |
| 162 | // Save recording locally as backup |
| 163 | const recordingId = `track_${Date.now()}`; |
| 164 | const jsonData = JSON.stringify(trackingLog, null, 2); |
| 165 | const dataUrl = 'data:application/json;charset=utf-8,' + encodeURIComponent(jsonData); |
| 166 | |
| 167 | chrome.downloads.download({ |
| 168 | url: dataUrl, |
| 169 | filename: `inverseui_${recordingId}.json`, |
| 170 | saveAs: true |
| 171 | }); |
| 172 | |
| 173 | // Determine error details |
| 174 | const errorCode = error.name || 'UNKNOWN_ERROR'; |
| 175 | const errorMessage = error.message || 'An unknown error occurred'; |
| 176 | const httpStatus = error.status || ''; |
| 177 | |
| 178 | // Build error page URL with details |
| 179 | const errorUrl = new URL(`${API_CONFIG.RESULTS.viewUrl.replace('/track/', '/error')}`); |
| 180 | errorUrl.searchParams.set('code', errorCode); |
| 181 | errorUrl.searchParams.set('message', errorMessage); |
| 182 | errorUrl.searchParams.set('recording_id', recordingId); |
| 183 | errorUrl.searchParams.set('actions_count', trackingLog.length.toString()); |
| 184 | errorUrl.searchParams.set('timestamp', Date.now().toString()); |
| 185 | |
| 186 | if (httpStatus) { |
| 187 | errorUrl.searchParams.set('status', httpStatus.toString()); |
| 188 | } |
| 189 | |
| 190 | // Open error page on InverseUI website |
| 191 | chrome.tabs.create({ |
| 192 | url: errorUrl.toString() |
| 193 | }); |
| 194 | |
| 195 | // Also show notification |
| 196 | chrome.notifications.create({ |
| 197 | type: 'basic', |
| 198 | iconUrl: chrome.runtime.getURL('icons/icon-48.png'), |
| 199 | title: 'Upload Failed', |
| 200 | message: 'Failed to send to InverseUI. Opening error details...', |
| 201 | priority: 2 |
| 202 | }); |
| 203 | |
| 204 | return { success: false, error: error.message }; |
| 205 | } |
no outgoing calls
no test coverage detected