feat: adding try catch code

This commit is contained in:
carlos
2022-06-04 15:37:45 -04:00
parent 013cbc6346
commit c088e00645
4 changed files with 21 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
const fs = require('fs')
const path = require('path')
const csvToJson = (csv) => {
const lines = csv.split(/\r\n|\n/)
@@ -17,6 +18,8 @@ const csvToJson = (csv) => {
}
exports.readFile = async (pathFile) => {
const checkExt = path.extname(pathFile)
if (checkExt !== '.csv') throw new Error('Wrong extension file')
const result = new Promise((resolve, reject) => {
fs.readFile(`${pathFile}`, 'utf8', (err, data) => {
if (err) {