1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-15 18:54:36 +00:00

fix(*): post request bodies as JSON

This commit is contained in:
Krishna Acondy
2021-01-28 20:36:41 +00:00
parent 3c894c4147
commit 2ea49a425f
3 changed files with 22 additions and 16 deletions

View File

@@ -185,7 +185,8 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({
};
return adapter.request("common/sendObj", invalidData).catch((e) => e);
},
assertion: (error: any) => !!error && !!error.error && !!error.error.message
assertion: (error: any) =>
!!error && !!error.error && !!error.error.message
},
{
title: "Single string value",

View File

@@ -165,7 +165,7 @@ export class ContextManager {
const { result: context } = await this.requestClient
.post<Context>(
`${this.serverUrl}/compute/contexts`,
JSON.stringify(requestBody),
requestBody,
accessToken
)
.catch((err) => {
@@ -216,7 +216,7 @@ export class ContextManager {
const { result: context } = await this.requestClient
.post<Context>(
`${this.serverUrl}/launcher/contexts`,
JSON.stringify(requestBody),
requestBody,
accessToken
)
.catch((err) => {
@@ -275,11 +275,11 @@ export class ContextManager {
// https://developer.sas.com/apis/rest/Compute/#update-a-context-definition
return await this.requestClient.put<Context>(
`/compute/contexts/${context.id}`,
JSON.stringify({
{
...context,
...editedContext,
attributes: { ...context.attributes, ...editedContext.attributes }
}),
},
accessToken,
{ 'If-Match': etag }
)

View File

@@ -9,7 +9,8 @@ import {
EditContextInput,
JobDefinition,
PollOptions,
ComputeJobExecutionError
ComputeJobExecutionError,
JobExecutionError
} from './types'
import { formatDataForRequest } from './utils/formatDataForRequest'
import { SessionManager } from './SessionManager'
@@ -560,10 +561,10 @@ export class SASViyaApiClient {
result: createFolderResponse
} = await this.requestClient.post<Folder>(
`/folders/folders?parentFolderUri=${parentFolderUri}`,
JSON.stringify({
{
name: folderName,
type: 'folder'
}),
},
accessToken
)
@@ -943,12 +944,12 @@ export class SASViyaApiClient {
jobArguments[`_webin_name${index + 1}`] = fileInfo.tableName
})
const postJobRequestBody = JSON.stringify({
const postJobRequestBody = {
name: `exec-${jobName}`,
description: 'Powered by SASjs',
jobDefinition,
arguments: jobArguments
})
}
const { result: postedJob, etag } = await this.requestClient.post<Job>(
`${this.serverUrl}/jobExecution/jobs?_action=wait`,
postJobRequestBody,
@@ -978,7 +979,11 @@ export class SASViyaApiClient {
.then((res: any) => res.result.items.map((i: any) => i.line).join('\n'))
}
if (jobStatus === 'failed') {
return Promise.reject({ error: currentJob.error, log })
throw new JobExecutionError(
currentJob.error?.errorCode,
currentJob.error?.message,
log
)
}
return { result: jobResult?.result, log }
}
@@ -1015,7 +1020,7 @@ export class SASViyaApiClient {
accessToken?: string,
pollOptions?: PollOptions
) {
let POLL_INTERVAL = 100
let POLL_INTERVAL = 300
let MAX_POLL_COUNT = 1000
if (pollOptions) {
@@ -1201,21 +1206,21 @@ export class SASViyaApiClient {
const { result: folder } = await this.requestClient
.patch<Folder>(
`${this.serverUrl}${url}`,
JSON.stringify({
{
id: sourceFolderId,
name: targetFolderName,
parentFolderUri: targetParentFolderUri
}),
},
accessToken
)
.catch((err) => {
if (err.code && err.code === 'ENOTFOUND') {
const notFoundError = {
body: JSON.stringify({
body: {
message: `Folder '${sourceFolder
.split('/')
.pop()}' was not found.`
})
}
}
throw notFoundError