Handle non-csv file error

This commit is contained in:
Mel O'Hagan 2022-08-30 15:18:44 +01:00
parent 1e70f6afb4
commit 8c40394d35
1 changed files with 18 additions and 7 deletions

View File

@ -130,14 +130,25 @@ module S3Module {
})
.createReadStream()
return new Promise((resolve, reject) => {
stream
.on("error", (err: Error) => {
reject(err)
})
.on("finish", async () => {
resolve(csv().fromStream(stream))
let csvError = false
return new Promise(async (resolve, reject) => {
stream.on("error", (err: Error) => {
reject(err)
})
const response = csv()
.fromStream(stream)
.on("error", () => {
csvError = true
})
stream.on("finish", () => {
resolve(response)
})
}).catch(err => {
if (csvError) {
throw new Error("Could not read CSV")
} else {
throw err
}
})
}
}