1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-16 08:30:07 +00:00

fix: double parsing issue in sas9 debug mode fixed

This commit is contained in:
2021-08-18 00:05:52 +05:00
parent 8464e506e0
commit 63e220c5be
2 changed files with 13 additions and 16 deletions

View File

@@ -2,7 +2,8 @@ import { ServerType } from '@sasjs/utils/types'
import { import {
ErrorResponse, ErrorResponse,
JobExecutionError, JobExecutionError,
LoginRequiredError LoginRequiredError,
WeboutResponseError
} from '../types/errors' } from '../types/errors'
import { generateFileUploadForm } from '../file/generateFileUploadForm' import { generateFileUploadForm } from '../file/generateFileUploadForm'
import { generateTableUploadForm } from '../file/generateTableUploadForm' import { generateTableUploadForm } from '../file/generateTableUploadForm'
@@ -102,10 +103,11 @@ export class WebJobExecutor extends BaseJobExecutor {
const requestPromise = new Promise((resolve, reject) => { const requestPromise = new Promise((resolve, reject) => {
this.requestClient!.post(apiUrl, formData, undefined) this.requestClient!.post(apiUrl, formData, undefined)
.then(async (res) => { .then(async (res: any) => {
console.log(106, res)
if (this.serverType === ServerType.SasViya && config.debug) { if (this.serverType === ServerType.SasViya && config.debug) {
const jsonResponse = await parseSasViyaDebugResponse( const jsonResponse = await parseSasViyaDebugResponse(
res.result as string, res.result,
this.requestClient, this.requestClient,
this.serverUrl this.serverUrl
) )
@@ -113,18 +115,19 @@ export class WebJobExecutor extends BaseJobExecutor {
resolve(jsonResponse) resolve(jsonResponse)
} }
if (this.serverType === ServerType.Sas9 && config.debug) { if (this.serverType === ServerType.Sas9 && config.debug) {
const jsonResponse = parseWeboutResponse(res.result as string) let jsonResponse
if (jsonResponse === '') { if (typeof res.result === 'string') {
throw new Error( jsonResponse = parseWeboutResponse(res.result)
'Valid JSON could not be extracted from response.' if (jsonResponse === '') throw new WeboutResponseError(apiUrl)
) } else {
jsonResponse = res.result
} }
getValidJson(jsonResponse) getValidJson(jsonResponse)
this.appendRequest(res, sasJob, config.debug) this.appendRequest(res, sasJob, config.debug)
resolve(res.result) resolve(res.result)
} }
getValidJson(res.result as string) getValidJson(res.result)
this.appendRequest(res, sasJob, config.debug) this.appendRequest(res, sasJob, config.debug)
resolve(res.result) resolve(res.result)
}) })

View File

@@ -429,13 +429,7 @@ export class RequestClient implements HttpClient {
} }
} catch { } catch {
try { try {
const weboutResponse = parseWeboutResponse(response.data) parsedResponse = JSON.parse(parseWeboutResponse(response.data))
if (weboutResponse === '') {
throw new Error('Valid JSON could not be extracted from response.')
}
const jsonResponse = getValidJson(weboutResponse)
parsedResponse = jsonResponse
} catch { } catch {
parsedResponse = response.data parsedResponse = response.data
} }