From b3ef50e9eb83fc78a4497e799f0a09f7315ed5e0 Mon Sep 17 00:00:00 2001 From: Yury Shkoda Date: Tue, 30 Mar 2021 11:04:18 +0300 Subject: [PATCH] fix(fetch-log): fixed response parsing --- src/SASjs.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/SASjs.ts b/src/SASjs.ts index ae0b824..393184b 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -12,6 +12,7 @@ import { ComputeJobExecutor, JesJobExecutor } from './job-execution' +import { ErrorResponse } from './types/errors' const defaultConfig: SASjsConfig = { serverUrl: '', @@ -705,9 +706,27 @@ export default class SASjs { * @param accessToken - an access token for an authorized user. */ public async fetchLogFileContent(logUrl: string, accessToken?: string) { - return await this.requestClient!.get(logUrl, accessToken).then((res) => - JSON.stringify(res.result) - ) + return await this.requestClient!.get(logUrl, accessToken).then((res) => { + if (!res) + return Promise.reject( + new ErrorResponse( + 'Error while fetching log. Response was not provided.' + ) + ) + + try { + const result = JSON.stringify(res.result) + + return result + } catch (err) { + return Promise.reject( + new ErrorResponse( + 'Error while fetching log. The result is not valid.', + err + ) + ) + } + }) } public getSasRequests() {