From c3ce138c9bd8ffd4f8a6b1a666ad4d078a287481 Mon Sep 17 00:00:00 2001 From: Patrick Joyce Date: Sun, 18 Feb 2024 14:43:46 -0500 Subject: [PATCH] rm redundant checks --- src/lib/DataConverter.svelte | 33 +++++++++------------------------ src/lib/DataUtils.ts | 12 +----------- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/lib/DataConverter.svelte b/src/lib/DataConverter.svelte index 34144f6..5c54081 100644 --- a/src/lib/DataConverter.svelte +++ b/src/lib/DataConverter.svelte @@ -10,33 +10,18 @@ let kmlDownloadUrl: string = ''; async function handleExport() { - if (query.trim() === '') { - return; - } - processing.set(true); - errorMessage.set(''); - csvDownloadUrl = ''; - xlsxDownloadUrl = ''; - kmlDownloadUrl = ''; - + if (query.trim() === '') return; try { + processing.set(true); const data = await fetchData(query); - if (data && data.length > 0) { - // Process data for CSV - csvDownloadUrl = exportCSV(data); - // Process data for XLSX - xlsxDownloadUrl = exportXLSX(data); - // Process data for KML - kmlDownloadUrl = query.includes('GetSearchResults') ? exportKML(data) : ''; - } else { - throw new Error('No data available for export.'); - } + // Process data for CSV + csvDownloadUrl = exportCSV(data); + // Process data for XLSX + xlsxDownloadUrl = exportXLSX(data); + // Process data for KML + kmlDownloadUrl = query.includes('GetSearchResults') ? exportKML(data) : ''; } catch (error) { - if (error instanceof Error) { - errorMessage.set(error.message || 'Failed to export data.'); - } else { - errorMessage.set('Failed to export data.'); - } + errorMessage.set(error instanceof Error ? error.message : 'Failed to export data.'); } finally { processing.set(false); } diff --git a/src/lib/DataUtils.ts b/src/lib/DataUtils.ts index 2cd30c2..d30a19a 100644 --- a/src/lib/DataUtils.ts +++ b/src/lib/DataUtils.ts @@ -34,18 +34,11 @@ export async function fetchData(query: string): Promise { } return data; } catch (error) { - if (error instanceof Error) { - throw new Error(error.message || 'Error loading data'); - } else { - throw new Error('Error loading data'); - } + throw new Error(error instanceof Error ? error.message : 'Error loading data'); } } export function exportCSV(data: any[]): string { - if (!Array.isArray(data) || data.length === 0) { - throw new Error('No data found'); - } const processedData = processExportData(data); const wb = XLSX.utils.book_new(); const ws = XLSX.utils.json_to_sheet(processedData); @@ -56,9 +49,6 @@ export function exportCSV(data: any[]): string { } export function exportXLSX(data: any[]): string { - if (!Array.isArray(data) || data.length === 0) { - throw new Error('No data found'); - } const processedData = processExportData(data); const wb = XLSX.utils.book_new(); const ws = XLSX.utils.json_to_sheet(processedData);