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

fix: replace isValidJson with getValidJson

This commit is contained in:
2021-07-18 23:24:22 +05:00
parent 7ac7c5e52b
commit 5347aeba09
6 changed files with 14 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
import { isUrl, isValidJson, parseSasViyaDebugResponse } from './utils'
import { isUrl, getValidJson, parseSasViyaDebugResponse } from './utils'
import { UploadFile } from './types/UploadFile'
import { ErrorResponse, LoginRequiredError } from './types/errors'
import { RequestClient } from './request/RequestClient'
@@ -77,12 +77,12 @@ export class FileUploader {
this.sasjsConfig.serverUrl
)
return typeof jsonResponse === 'string'
? isValidJson(jsonResponse)
? getValidJson(jsonResponse)
: jsonResponse
}
return typeof res.result === 'string'
? isValidJson(res.result)
? getValidJson(res.result)
: res.result
//TODO: append to SASjs requests

View File

@@ -10,7 +10,7 @@ import { RequestClient } from '../request/RequestClient'
import { SASViyaApiClient } from '../SASViyaApiClient'
import {
isRelativePath,
isValidJson,
getValidJson,
parseSasViyaDebugResponse
} from '../utils'
import { BaseJobExecutor } from './JobExecutor'
@@ -115,11 +115,11 @@ export class WebJobExecutor extends BaseJobExecutor {
)
}
isValidJson(jsonResponse)
getValidJson(jsonResponse)
this.appendRequest(res, sasJob, config.debug)
resolve(res.result)
}
isValidJson(res.result as string)
getValidJson(res.result as string)
this.appendRequest(res, sasJob, config.debug)
resolve(res.result)
})

View File

@@ -11,7 +11,7 @@ import {
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
import { prefixMessage } from '@sasjs/utils/error'
import { SAS9AuthError } from '../types/errors/SAS9AuthError'
import { isValidJson } from '../utils'
import { getValidJson } from '../utils'
export interface HttpClient {
get<T>(
@@ -429,7 +429,7 @@ export class RequestClient implements HttpClient {
throw new Error('Valid JSON could not be extracted from response.')
}
const jsonResponse = isValidJson(weboutResponse)
const jsonResponse = getValidJson(weboutResponse)
parsedResponse = jsonResponse
} catch {
parsedResponse = response.data

View File

@@ -1,4 +1,4 @@
import { isValidJson } from '../../utils'
import { getValidJson } from '../../utils'
describe('jsonValidator', () => {
it('should not throw an error with an valid json', () => {
@@ -6,7 +6,7 @@ describe('jsonValidator', () => {
test: 'test'
}
expect(isValidJson(json)).toBe(json)
expect(getValidJson(json)).toBe(json)
})
it('should not throw an error with an valid json string', () => {
@@ -14,7 +14,7 @@ describe('jsonValidator', () => {
test: 'test'
}
expect(isValidJson(JSON.stringify(json))).toStrictEqual(json)
expect(getValidJson(JSON.stringify(json))).toStrictEqual(json)
})
it('should throw an error with an invalid json', () => {
@@ -22,7 +22,7 @@ describe('jsonValidator', () => {
expect(() => {
try {
isValidJson(json)
getValidJson(json)
} catch (err) {
throw new Error()
}

View File

@@ -2,7 +2,7 @@
* Checks if string is in valid JSON format else throw error.
* @param str - string to check.
*/
export const isValidJson = (str: string | object) => {
export const getValidJson = (str: string | object) => {
try {
if (typeof str === 'object') return str

View File

@@ -12,5 +12,5 @@ export * from './serialize'
export * from './splitChunks'
export * from './parseWeboutResponse'
export * from './fetchLogByChunks'
export * from './isValidJson'
export * from './getValidJson'
export * from './parseViyaDebugResponse'