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

fix: if response is not valid json throw error #409

This commit is contained in:
2021-06-21 00:45:37 +05:00
parent 9b976d48ca
commit 93c9a34591
4 changed files with 35 additions and 2 deletions

View File

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