FEAT: Adicionado resposta da API quando erro a coluna Erro
This commit is contained in:
parent
5b98394ee2
commit
cb78257f3f
@ -215,6 +215,18 @@ function cleanCsvValue(value) {
|
||||
return text.includes('"') ? text.replace(/"/g, "'") : text;
|
||||
}
|
||||
|
||||
function formatApiErrorResponse(error) {
|
||||
const responseData = error && error.response && error.response.data;
|
||||
if (responseData !== undefined && responseData !== null) {
|
||||
if (typeof responseData === 'string') return responseData;
|
||||
if (responseData.error) return responseData.error;
|
||||
if (responseData.message) return responseData.message;
|
||||
return JSON.stringify(responseData);
|
||||
}
|
||||
|
||||
return error && (error.message || String(error));
|
||||
}
|
||||
|
||||
async function countValidLines(inputPath) {
|
||||
await discoverDataType(inputPath);
|
||||
const rows = readRows(inputPath);
|
||||
@ -261,7 +273,7 @@ async function processCsvFile(jobId, inputPath, originalName) {
|
||||
outStream.write(outCols.join(';') + '\n');
|
||||
incrementProcessed(jobId);
|
||||
} catch (err) {
|
||||
const errMsg = cleanCsvValue(err && (err.message || String(err)));
|
||||
const errMsg = cleanCsvValue(formatApiErrorResponse(err));
|
||||
const outCols = ['', '', '', errMsg, ...cols].map(cleanCsvValue);
|
||||
outStream.write(outCols.join(';') + '\n');
|
||||
incrementErrors(jobId);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user