Skip to content

Commit

Permalink
fix(north-CsvToHttp): Remove httpbody as a class variable #962
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Tondolo committed Jan 7, 2021
1 parent b4fafc9 commit 7781528
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/north/CsvToHttp/CsvToHttp.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class CsvToHttp extends ApiHandler {
this.csvDelimiter = csvDelimiter
this.proxy = this.getProxy(proxy)

this.httpBody = []
this.canHandleFiles = true
this.canHandleValues = false
}
Expand All @@ -59,11 +58,10 @@ class CsvToHttp extends ApiHandler {

// The csv parsing is a success so we begin to map the content
// Initialize the body to an empty array
this.httpBody = []
this.convertToHttpBody(csvDataParsed)
const httpBody = this.convertToHttpBody(csvDataParsed)

if (this.httpBody.length !== 0) {
if (!await this.sendData()) {
if (httpBody.length !== 0) {
if (!await this.sendData(httpBody)) {
this.logger.error('Impossible to send data')
return ApiHandler.STATUS.LOGIC_ERROR
}
Expand All @@ -90,7 +88,6 @@ class CsvToHttp extends ApiHandler {
error: (error) => {
this.logger.error(error)
reject()
return []
},
step: (step) => {
csvDataParsed.push(step.data)
Expand All @@ -107,6 +104,7 @@ class CsvToHttp extends ApiHandler {
* @return {void}
*/
convertToHttpBody(jsonObject) {
const httpBody = []
// Log all headers in the csv file and log the value ine the mapping not present in headers
this.logger.silly(`All available headers are: ${Object.keys(jsonObject[0])}`)

Expand All @@ -122,9 +120,10 @@ class CsvToHttp extends ApiHandler {

// Test the result of the mapping/convertion before add it in the httpBody
if (response) {
this.httpBody.push(response)
httpBody.push(response)
}
})
return httpBody
}

/**
Expand Down Expand Up @@ -178,19 +177,20 @@ class CsvToHttp extends ApiHandler {
}

/**
* @param {Array} httpBody - Body to send
* @return {Promise} - Promise
*/
sendData() {
sendData(httpBody) {
return new Promise((resolve, reject) => {
try {
if (this.httpBody.length > this.bodyMaxLength) {
if (httpBody.length > this.bodyMaxLength) {
// Divide the current body in array of maximun maxLength elements
let i = 0
for (i; i < this.httpBody.length; i += this.bodyMaxLength) {
this.sendRequest(this.httpBody.slice(i, i + this.bodyMaxLength - 1))
for (i; i < httpBody.length; i += this.bodyMaxLength) {
this.sendRequest(httpBody.slice(i, i + this.bodyMaxLength - 1))
}
} else {
this.sendRequest(this.httpBody)
this.sendRequest(httpBody)
}
resolve(true)
} catch (error) {
Expand Down

0 comments on commit 7781528

Please sign in to comment.