diff --git a/src/job-execution/WebJobExecutor.ts b/src/job-execution/WebJobExecutor.ts
index 30a6e2f..91a0fc8 100644
--- a/src/job-execution/WebJobExecutor.ts
+++ b/src/job-execution/WebJobExecutor.ts
@@ -8,7 +8,11 @@ import { generateFileUploadForm } from '../file/generateFileUploadForm'
import { generateTableUploadForm } from '../file/generateTableUploadForm'
import { RequestClient } from '../request/RequestClient'
import { SASViyaApiClient } from '../SASViyaApiClient'
-import { isRelativePath, isValidJson } from '../utils'
+import {
+ isRelativePath,
+ isValidJson,
+ parseSasViyaDebugResponse
+} from '../utils'
import { BaseJobExecutor } from './JobExecutor'
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
@@ -95,8 +99,10 @@ export class WebJobExecutor extends BaseJobExecutor {
this.requestClient!.post(apiUrl, formData, undefined)
.then(async (res) => {
if (this.serverType === ServerType.SasViya && config.debug) {
- const jsonResponse = await this.parseSasViyaDebugResponse(
- res.result as string
+ const jsonResponse = await parseSasViyaDebugResponse(
+ res.result as string,
+ this.requestClient,
+ this.serverUrl
)
this.appendRequest(res, sasJob, config.debug)
resolve(jsonResponse)
@@ -151,20 +157,6 @@ export class WebJobExecutor extends BaseJobExecutor {
return requestPromise
}
- private parseSasViyaDebugResponse = async (response: string) => {
- const iframeStart = response.split(
- '')[0] : null
- if (!jsonUrl) {
- throw new Error('Unable to find webout file URL.')
- }
-
- return this.requestClient
- .get(this.serverUrl + jsonUrl, undefined)
- .then((res) => res.result)
- }
-
private async getJobUri(sasJob: string) {
if (!this.sasViyaApiClient) return ''
let uri = ''
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 3f6ec1d..9cc5244 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -13,3 +13,4 @@ export * from './splitChunks'
export * from './parseWeboutResponse'
export * from './fetchLogByChunks'
export * from './isValidJson'
+export * from './parseViyaDebugResponse'
diff --git a/src/utils/parseViyaDebugResponse.ts b/src/utils/parseViyaDebugResponse.ts
new file mode 100644
index 0000000..3137995
--- /dev/null
+++ b/src/utils/parseViyaDebugResponse.ts
@@ -0,0 +1,29 @@
+import { RequestClient } from '../request/RequestClient'
+
+/**
+ * When querying a Viya job using the Web approach (as opposed to using the APIs) with _DEBUG enabled,
+ * the first response contains the log with the content in an iframe. Therefore when debug is enabled,
+ * and the serverType is VIYA, and useComputeApi is null (WEB), we call this function to extract the
+ * (_webout) content from the iframe.
+ * @param response - first response from viya job
+ * @param requestClient
+ * @param serverUrl
+ * @returns
+ */
+export const parseSasViyaDebugResponse = async (
+ response: string,
+ requestClient: RequestClient,
+ serverUrl: string
+) => {
+ const iframeStart = response.split(
+ '')[0] : null
+ if (!jsonUrl) {
+ throw new Error('Unable to find webout file URL.')
+ }
+
+ return requestClient
+ .get(serverUrl + jsonUrl, undefined)
+ .then((res) => res.result)
+}