1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-10 22:00:05 +00:00

fix: created sasjsJobExecutor class and overrided parseResponse for sasjsRequestClient

This commit is contained in:
2022-08-23 15:47:50 +05:00
parent 4a319f1aef
commit c551cd0311
8 changed files with 208 additions and 96 deletions

View File

@@ -1,9 +1,12 @@
import { RequestClient } from './RequestClient'
import { AxiosResponse } from 'axios'
import { SASJS_LOGS_SEPARATOR, getValidJson } from '../utils'
/**
* Specific request client for SASJS.
* Append tokens in headers.
*/
export class SasjsRequestClient extends RequestClient {
getHeaders = (accessToken: string | undefined, contentType: string) => {
const headers: any = {}
@@ -20,4 +23,32 @@ export class SasjsRequestClient extends RequestClient {
return headers
}
protected parseResponse<T>(response: AxiosResponse<any>) {
const etag = response?.headers ? response.headers['etag'] : ''
let parsedResponse
let log
try {
if (typeof response.data === 'string') {
parsedResponse = JSON.parse(response.data)
} else {
parsedResponse = response.data
}
} catch {
if (response.data.includes(SASJS_LOGS_SEPARATOR)) {
parsedResponse = getValidJson(
response.data.split(SASJS_LOGS_SEPARATOR)[0]
)
log = response.data.split(SASJS_LOGS_SEPARATOR)[1]
} else parsedResponse = response.data
}
return {
result: parsedResponse as T,
log,
etag,
status: response.status
}
}
}