mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-09 05:20:05 +00:00
fix: handled updated sasjs response
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import {
|
||||
getValidJson,
|
||||
parseSasViyaDebugResponse,
|
||||
parseWeboutResponse
|
||||
parseWeboutResponse,
|
||||
SASJS_LOGS_SEPARATOR
|
||||
} from '../utils'
|
||||
import { UploadFile } from '../types/UploadFile'
|
||||
import {
|
||||
@@ -80,9 +81,29 @@ export class FileUploader extends BaseJobExecutor {
|
||||
this.requestClient
|
||||
.post(uploadUrl, formData, undefined, 'application/json', headers)
|
||||
.then(async (res: any) => {
|
||||
this.requestClient.appendRequest(res, sasJob, config.debug)
|
||||
const parsedSasjsLog =
|
||||
this.serverType === ServerType.Sasjs
|
||||
? res.log?.split(SASJS_LOGS_SEPARATOR)[1]
|
||||
: res.result.log
|
||||
|
||||
let jsonResponse = res.result
|
||||
const parsedSasjsServerWebout =
|
||||
this.serverType === ServerType.Sasjs
|
||||
? typeof res.result === 'string'
|
||||
? getValidJson(res.log?.split(SASJS_LOGS_SEPARATOR)[0])
|
||||
: res.result
|
||||
: undefined
|
||||
|
||||
const resObj =
|
||||
this.serverType === ServerType.Sasjs
|
||||
? {
|
||||
result: parsedSasjsServerWebout,
|
||||
log: parsedSasjsLog
|
||||
}
|
||||
: res
|
||||
|
||||
this.requestClient.appendRequest(resObj, sasJob, config.debug)
|
||||
|
||||
let jsonResponse = resObj.result
|
||||
|
||||
if (config.debug) {
|
||||
switch (this.serverType) {
|
||||
@@ -99,25 +120,7 @@ export class FileUploader extends BaseJobExecutor {
|
||||
? parseWeboutResponse(res.result, uploadUrl)
|
||||
: res.result
|
||||
break
|
||||
case ServerType.Sasjs:
|
||||
if (typeof res.result._webout === 'object') {
|
||||
jsonResponse = res.result._webout
|
||||
} else {
|
||||
const webout = parseWeboutResponse(
|
||||
res.result._webout,
|
||||
uploadUrl
|
||||
)
|
||||
jsonResponse = getValidJson(webout)
|
||||
}
|
||||
break
|
||||
}
|
||||
} else if (this.serverType === ServerType.Sasjs) {
|
||||
jsonResponse = getValidJson(res.result._webout)
|
||||
} else {
|
||||
jsonResponse =
|
||||
typeof res.result === 'string'
|
||||
? getValidJson(res.result)
|
||||
: res.result
|
||||
}
|
||||
|
||||
resolve(jsonResponse)
|
||||
|
||||
@@ -17,7 +17,8 @@ import {
|
||||
isRelativePath,
|
||||
parseSasViyaDebugResponse,
|
||||
appendExtraResponseAttributes,
|
||||
getValidJson
|
||||
getValidJson,
|
||||
SASJS_LOGS_SEPARATOR
|
||||
} from '../utils'
|
||||
import { BaseJobExecutor } from './JobExecutor'
|
||||
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
||||
@@ -164,33 +165,37 @@ export class WebJobExecutor extends BaseJobExecutor {
|
||||
contentType
|
||||
)
|
||||
.then(async (res: any) => {
|
||||
const parsedSasjsServerLog =
|
||||
const parsedSasjsLog =
|
||||
this.serverType === ServerType.Sasjs
|
||||
? res.result.log.map((logLine: any) => logLine.line).join('\n')
|
||||
? res.log?.split(SASJS_LOGS_SEPARATOR)[1]
|
||||
: res.result.log
|
||||
|
||||
const parsedSasjsServerWebout =
|
||||
this.serverType === ServerType.Sasjs
|
||||
? typeof res.result === 'string'
|
||||
? getValidJson(res.log?.split(SASJS_LOGS_SEPARATOR)[0])
|
||||
: res.result
|
||||
: undefined
|
||||
|
||||
const resObj =
|
||||
this.serverType === ServerType.Sasjs
|
||||
? {
|
||||
result: res.result._webout,
|
||||
log: parsedSasjsServerLog
|
||||
result: parsedSasjsServerWebout,
|
||||
log: parsedSasjsLog
|
||||
}
|
||||
: res
|
||||
|
||||
if (
|
||||
this.serverType === ServerType.Sasjs &&
|
||||
res.result._webout.length < 1
|
||||
) {
|
||||
if (this.serverType === ServerType.Sasjs && res.result.length < 1) {
|
||||
throw new JobExecutionError(
|
||||
0,
|
||||
`No webout was returned by job ${program}. Server type is SASJS and the calling function is WebJobExecutor. Please check the SAS log for more info.`,
|
||||
parsedSasjsServerLog
|
||||
parsedSasjsLog
|
||||
)
|
||||
}
|
||||
|
||||
this.requestClient!.appendRequest(resObj, sasJob, config.debug)
|
||||
|
||||
let jsonResponse = res.result
|
||||
let jsonResponse = resObj.result
|
||||
|
||||
if (config.debug) {
|
||||
switch (this.serverType) {
|
||||
@@ -207,21 +212,11 @@ export class WebJobExecutor extends BaseJobExecutor {
|
||||
? parseWeboutResponse(res.result, apiUrl)
|
||||
: res.result
|
||||
break
|
||||
case ServerType.Sasjs:
|
||||
if (typeof res.result._webout === 'object') {
|
||||
jsonResponse = res.result._webout
|
||||
} else {
|
||||
const webout = parseWeboutResponse(res.result._webout, apiUrl)
|
||||
jsonResponse = getValidJson(webout)
|
||||
}
|
||||
break
|
||||
}
|
||||
} else if (this.serverType === ServerType.Sasjs) {
|
||||
jsonResponse = getValidJson(res.result._webout)
|
||||
}
|
||||
|
||||
const responseObject = appendExtraResponseAttributes(
|
||||
{ result: jsonResponse, log: parsedSasjsServerLog },
|
||||
{ result: jsonResponse, log: parsedSasjsLog },
|
||||
extraResponseAttributes
|
||||
)
|
||||
resolve(responseObject)
|
||||
@@ -261,9 +256,7 @@ export class WebJobExecutor extends BaseJobExecutor {
|
||||
})
|
||||
|
||||
if (loginCallback) await loginCallback()
|
||||
} else {
|
||||
reject(new ErrorResponse(e?.message, e))
|
||||
}
|
||||
} else reject(new ErrorResponse(e?.message, e))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user