From 591e1ebc098016c997eb0ab956a2bb1438824d41 Mon Sep 17 00:00:00 2001 From: sabir_hassan Date: Thu, 27 May 2021 21:59:40 +0500 Subject: [PATCH] fix: callback type checking fixes #304 --- src/SASjs.ts | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/SASjs.ts b/src/SASjs.ts index 574e374..3105182 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -550,31 +550,41 @@ export default class SASjs { ...this.sasjsConfig, ...config } - - if (config.serverType === ServerType.SasViya && config.contextName) { - if (config.useComputeApi) { - return await this.computeJobExecutor!.execute( - sasJob, - data, - config, - loginRequiredCallback, - accessToken - ) + if ( + typeof loginRequiredCallback === 'function' || + typeof loginRequiredCallback === 'undefined' + ) { + if (config.serverType === ServerType.SasViya && config.contextName) { + if (config.useComputeApi) { + return await this.computeJobExecutor!.execute( + sasJob, + data, + config, + loginRequiredCallback, + accessToken + ) + } else { + return await this.jesJobExecutor!.execute( + sasJob, + data, + config, + loginRequiredCallback, + accessToken + ) + } } else { - return await this.jesJobExecutor!.execute( + return await this.webJobExecutor!.execute( sasJob, data, config, - loginRequiredCallback, - accessToken + loginRequiredCallback ) } } else { - return await this.webJobExecutor!.execute( - sasJob, - data, - config, - loginRequiredCallback + return Promise.reject( + new ErrorResponse( + `Invalid loginRequiredCallback parameter was provided. Expected Callback function but found ${typeof loginRequiredCallback}` + ) ) } }