diff --git a/src/FileUploader.ts b/src/FileUploader.ts index 922571a..7001bcb 100644 --- a/src/FileUploader.ts +++ b/src/FileUploader.ts @@ -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 diff --git a/src/job-execution/WebJobExecutor.ts b/src/job-execution/WebJobExecutor.ts index 91a0fc8..98063fa 100644 --- a/src/job-execution/WebJobExecutor.ts +++ b/src/job-execution/WebJobExecutor.ts @@ -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) }) diff --git a/src/request/RequestClient.ts b/src/request/RequestClient.ts index 5bf7414..d1946f7 100644 --- a/src/request/RequestClient.ts +++ b/src/request/RequestClient.ts @@ -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( @@ -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 diff --git a/src/test/utils/isValidJson.spec.ts b/src/test/utils/isValidJson.spec.ts index b7af712..1901ba1 100644 --- a/src/test/utils/isValidJson.spec.ts +++ b/src/test/utils/isValidJson.spec.ts @@ -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() } diff --git a/src/utils/isValidJson.ts b/src/utils/getValidJson.ts similarity index 81% rename from src/utils/isValidJson.ts rename to src/utils/getValidJson.ts index 253440f..738f679 100644 --- a/src/utils/isValidJson.ts +++ b/src/utils/getValidJson.ts @@ -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 diff --git a/src/utils/index.ts b/src/utils/index.ts index 9cc5244..9f70293 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -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'