mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-19 01:50:06 +00:00
fix: replace isValidJson with getValidJson
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { isUrl, isValidJson, parseSasViyaDebugResponse } from './utils'
|
import { isUrl, getValidJson, parseSasViyaDebugResponse } from './utils'
|
||||||
import { UploadFile } from './types/UploadFile'
|
import { UploadFile } from './types/UploadFile'
|
||||||
import { ErrorResponse, LoginRequiredError } from './types/errors'
|
import { ErrorResponse, LoginRequiredError } from './types/errors'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
@@ -77,12 +77,12 @@ export class FileUploader {
|
|||||||
this.sasjsConfig.serverUrl
|
this.sasjsConfig.serverUrl
|
||||||
)
|
)
|
||||||
return typeof jsonResponse === 'string'
|
return typeof jsonResponse === 'string'
|
||||||
? isValidJson(jsonResponse)
|
? getValidJson(jsonResponse)
|
||||||
: jsonResponse
|
: jsonResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeof res.result === 'string'
|
return typeof res.result === 'string'
|
||||||
? isValidJson(res.result)
|
? getValidJson(res.result)
|
||||||
: res.result
|
: res.result
|
||||||
|
|
||||||
//TODO: append to SASjs requests
|
//TODO: append to SASjs requests
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { RequestClient } from '../request/RequestClient'
|
|||||||
import { SASViyaApiClient } from '../SASViyaApiClient'
|
import { SASViyaApiClient } from '../SASViyaApiClient'
|
||||||
import {
|
import {
|
||||||
isRelativePath,
|
isRelativePath,
|
||||||
isValidJson,
|
getValidJson,
|
||||||
parseSasViyaDebugResponse
|
parseSasViyaDebugResponse
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { BaseJobExecutor } from './JobExecutor'
|
import { BaseJobExecutor } from './JobExecutor'
|
||||||
@@ -115,11 +115,11 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
isValidJson(jsonResponse)
|
getValidJson(jsonResponse)
|
||||||
this.appendRequest(res, sasJob, config.debug)
|
this.appendRequest(res, sasJob, config.debug)
|
||||||
resolve(res.result)
|
resolve(res.result)
|
||||||
}
|
}
|
||||||
isValidJson(res.result as string)
|
getValidJson(res.result as string)
|
||||||
this.appendRequest(res, sasJob, config.debug)
|
this.appendRequest(res, sasJob, config.debug)
|
||||||
resolve(res.result)
|
resolve(res.result)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
import { SAS9AuthError } from '../types/errors/SAS9AuthError'
|
import { SAS9AuthError } from '../types/errors/SAS9AuthError'
|
||||||
import { isValidJson } from '../utils'
|
import { getValidJson } from '../utils'
|
||||||
|
|
||||||
export interface HttpClient {
|
export interface HttpClient {
|
||||||
get<T>(
|
get<T>(
|
||||||
@@ -429,7 +429,7 @@ export class RequestClient implements HttpClient {
|
|||||||
throw new Error('Valid JSON could not be extracted from response.')
|
throw new Error('Valid JSON could not be extracted from response.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const jsonResponse = isValidJson(weboutResponse)
|
const jsonResponse = getValidJson(weboutResponse)
|
||||||
parsedResponse = jsonResponse
|
parsedResponse = jsonResponse
|
||||||
} catch {
|
} catch {
|
||||||
parsedResponse = response.data
|
parsedResponse = response.data
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { isValidJson } from '../../utils'
|
import { getValidJson } from '../../utils'
|
||||||
|
|
||||||
describe('jsonValidator', () => {
|
describe('jsonValidator', () => {
|
||||||
it('should not throw an error with an valid json', () => {
|
it('should not throw an error with an valid json', () => {
|
||||||
@@ -6,7 +6,7 @@ describe('jsonValidator', () => {
|
|||||||
test: 'test'
|
test: 'test'
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(isValidJson(json)).toBe(json)
|
expect(getValidJson(json)).toBe(json)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not throw an error with an valid json string', () => {
|
it('should not throw an error with an valid json string', () => {
|
||||||
@@ -14,7 +14,7 @@ describe('jsonValidator', () => {
|
|||||||
test: 'test'
|
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', () => {
|
it('should throw an error with an invalid json', () => {
|
||||||
@@ -22,7 +22,7 @@ describe('jsonValidator', () => {
|
|||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
try {
|
try {
|
||||||
isValidJson(json)
|
getValidJson(json)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error()
|
throw new Error()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* Checks if string is in valid JSON format else throw error.
|
* Checks if string is in valid JSON format else throw error.
|
||||||
* @param str - string to check.
|
* @param str - string to check.
|
||||||
*/
|
*/
|
||||||
export const isValidJson = (str: string | object) => {
|
export const getValidJson = (str: string | object) => {
|
||||||
try {
|
try {
|
||||||
if (typeof str === 'object') return str
|
if (typeof str === 'object') return str
|
||||||
|
|
||||||
@@ -12,5 +12,5 @@ export * from './serialize'
|
|||||||
export * from './splitChunks'
|
export * from './splitChunks'
|
||||||
export * from './parseWeboutResponse'
|
export * from './parseWeboutResponse'
|
||||||
export * from './fetchLogByChunks'
|
export * from './fetchLogByChunks'
|
||||||
export * from './isValidJson'
|
export * from './getValidJson'
|
||||||
export * from './parseViyaDebugResponse'
|
export * from './parseViyaDebugResponse'
|
||||||
|
|||||||
Reference in New Issue
Block a user