mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-08 11:28:34 +03:00
Working error handling; refactored a bit but same functionality
This commit is contained in:
@@ -59,13 +59,13 @@ class Controller {
|
||||
indexedData[item] = results[idx]
|
||||
})
|
||||
try {
|
||||
await exportToFile(fileDest, indexedData)
|
||||
return copy.success.export(fileDest)
|
||||
const message = await exportToFile(fileDest, indexedData)
|
||||
return message
|
||||
} catch (e) {
|
||||
return Promise.reject(e)
|
||||
}
|
||||
} else {
|
||||
return Promise.reject(new Error(copy.errors.export.writeFailed))
|
||||
throw new Error(copy.errors.export.writeFailed)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import R from 'ramda'
|
||||
import fs from 'file-system'
|
||||
import { promises as fs } from 'file-system'
|
||||
import copy from '../copy/en'
|
||||
|
||||
/* eslint-disable */
|
||||
@@ -16,13 +16,16 @@ function camelize (str) {
|
||||
})
|
||||
}
|
||||
|
||||
export function exportToFile(fileDest, data) {
|
||||
export async function exportToFile(fileDest, data) {
|
||||
const stringifiedData = JSON.stringify(data, null, 2)
|
||||
const filePath = `${fileDest}/export.json`
|
||||
|
||||
fs.writeFile(filePath, stringifiedData, (err) => {
|
||||
if (err) throw new Error(copy.errors.export.writeFailed)
|
||||
})
|
||||
try {
|
||||
await fs.writeFile(filePath, stringifiedData)
|
||||
return copy.success.export(filePath)
|
||||
} catch (err) {
|
||||
throw new Error(copy.errors.export.writeFailed)
|
||||
}
|
||||
}
|
||||
|
||||
export const fmtObj = R.curry(
|
||||
|
||||
Reference in New Issue
Block a user