From c47d0c978900677bb89280c1bc02f7eab858346b Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Fri, 11 Mar 2022 14:16:44 +0500 Subject: [PATCH 1/2] fix: return requestPromise from sas9JobExecutor #677 --- src/job-execution/Sas9JobExecutor.ts | 40 ++++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/job-execution/Sas9JobExecutor.ts b/src/job-execution/Sas9JobExecutor.ts index 2c866e2..eaade76 100644 --- a/src/job-execution/Sas9JobExecutor.ts +++ b/src/job-execution/Sas9JobExecutor.ts @@ -74,26 +74,32 @@ export class Sas9JobExecutor extends BaseJobExecutor { ? 'multipart/form-data; boundary=' + (formData as any)._boundary : 'text/plain' - return await this.sas9RequestClient!.post( - apiUrl, - formData, - undefined, - contentType, - { + const requestPromise = new Promise((resolve, reject) => + this.sas9RequestClient!.post(apiUrl, formData, undefined, contentType, { Accept: '*/*', Connection: 'Keep-Alive' - } + }) + .then((res: any) => { + //appending response to requests array that will be used for requests history reference + this.requestClient!.appendRequest(res, sasJob, config.debug) + resolve(res) + }) + .catch((err: any) => { + // by default error string is equal to actual error object + let errString = err + + // if error object contains non empty result attribute, set errString to result + if (err.result && err.result !== '') errString = err.result + // if there's no result but error message then set errString to error message + else if (err.message) errString = err.message + + //appending error to requests array that will be used for requests history reference + this.requestClient!.appendRequest(errString, sasJob, config.debug) + reject(new ErrorResponse(err?.message, err)) + }) ) - .then((res: any) => { - //appending response to requests array that will be used for requests history reference - this.requestClient!.appendRequest(res, sasJob, config.debug) - return res - }) - .catch((err: any) => { - //appending error to requests array that will be used for requests history reference - this.requestClient!.appendRequest(err, sasJob, config.debug) - return err - }) + + return requestPromise } private getRequestParams(config: any): any { From f6a621fe4609eee6df000ca3e5c6ad489dafe856 Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Fri, 11 Mar 2022 14:22:45 +0500 Subject: [PATCH 2/2] chore: update comments --- src/job-execution/Sas9JobExecutor.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/job-execution/Sas9JobExecutor.ts b/src/job-execution/Sas9JobExecutor.ts index eaade76..facc35c 100644 --- a/src/job-execution/Sas9JobExecutor.ts +++ b/src/job-execution/Sas9JobExecutor.ts @@ -80,7 +80,7 @@ export class Sas9JobExecutor extends BaseJobExecutor { Connection: 'Keep-Alive' }) .then((res: any) => { - //appending response to requests array that will be used for requests history reference + // appending response to requests array that will be used for requests history reference this.requestClient!.appendRequest(res, sasJob, config.debug) resolve(res) }) @@ -88,12 +88,12 @@ export class Sas9JobExecutor extends BaseJobExecutor { // by default error string is equal to actual error object let errString = err - // if error object contains non empty result attribute, set errString to result + // if error object contains non empty result attribute, set result to errString if (err.result && err.result !== '') errString = err.result - // if there's no result but error message then set errString to error message + // if there's no result but error message, set error message to errString else if (err.message) errString = err.message - //appending error to requests array that will be used for requests history reference + // appending error to requests array that will be used for requests history reference this.requestClient!.appendRequest(errString, sasJob, config.debug) reject(new ErrorResponse(err?.message, err)) })