1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-17 00:50:05 +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); 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", title: "Single string value",

View File

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

View File

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