Make import errors prettier and actually handle them

This commit is contained in:
Julia Friesel
2018-08-07 18:52:30 +02:00
parent 44cc448209
commit 77bda6bf53
2 changed files with 15 additions and 18 deletions
+11 -8
View File
@@ -42,11 +42,11 @@ async function openShareDialogAndExport() {
try { try {
data = getDataAsCsvDataUri() data = getDataAsCsvDataUri()
if (!data) { if (!data) {
return Alert.alert(labels.errors.noData) return alertError(labels.errors.noData)
} }
} catch (err) { } catch (err) {
console.error(err) console.error(err)
return Alert.alert(labels.errors.couldNotConvert) return alertError(labels.errors.couldNotConvert)
} }
try { try {
@@ -59,7 +59,7 @@ async function openShareDialogAndExport() {
}) })
} catch (err) { } catch (err) {
console.error(err) console.error(err)
return Alert.alert(labels.errors.problemSharing) return alertError(labels.errors.problemSharing)
} }
} }
@@ -83,14 +83,17 @@ async function getFileContentAndImport() {
try { try {
fileContent = await rnfs.readFile(fileInfo.uri, 'utf8') fileContent = await rnfs.readFile(fileInfo.uri, 'utf8')
} catch (err) { } catch (err) {
console.log(err) return alertError('Could not open file')
return Alert.alert('Could not open file')
} }
try { try {
importCsv(fileContent, false) await importCsv(fileContent, false)
Alert.alert('Data successfully imported') Alert.alert('Success', 'Data successfully imported')
} catch(err) { } catch(err) {
//TODO alertError(err.message)
} }
} }
function alertError(msg) {
Alert.alert('Error', msg)
}
+2 -8
View File
@@ -37,15 +37,9 @@ export default async function importCsv(csv, deleteFirst) {
}, {}) }, {})
} }
let cycleDays const cycleDays = await csvParser(config)
try {
cycleDays = await csvParser(config)
.fromString(csv) .fromString(csv)
.on('header', validateHeaders) .on('header', validateHeaders)
} catch(err) {
// TODO
console.log(err)
}
//remove symptoms where all fields are null //remove symptoms where all fields are null
putNullForEmptySymptoms(cycleDays) putNullForEmptySymptoms(cycleDays)
@@ -72,7 +66,7 @@ function tryToCreateCycleDay(day, i) {
try { try {
db.create('CycleDay', day) db.create('CycleDay', day)
} catch (err) { } catch (err) {
const msg = `Error for line ${i + 1}(${day.date}): ${err.message}` const msg = `Line ${i + 1}(${day.date}): ${err.message}`
throw new Error(msg) throw new Error(msg)
} }
} }