1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-03 10:40:06 +00:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Allan Bowe
6a52bbe560 Merge pull request #35 from sasjs/issue33
fix: makeRequest inconsistent response structure
2020-08-10 17:19:05 +02:00
Mihajlo Medjedovic
a5c725e677 fix: makeRequest incositent response structure 2020-08-10 17:05:10 +02:00
Krishna Acondy
f5e1907e28 feat(clear-requests): add function to clear debug requests 2020-08-08 14:27:40 +01:00
Krishna Acondy
f7a9b0cbb6 fix(compute-api): ignore 404s when requesting webout content 2020-08-08 14:26:09 +01:00
3 changed files with 26 additions and 7 deletions

View File

@@ -208,12 +208,15 @@ export class SASViyaApiClient {
debug = false
) {
silent = !debug;
const headers: any = {
"Content-Type": "application/json",
};
if (accessToken) {
headers.Authorization = `Bearer ${accessToken}`;
}
let executionSessionId: string;
const session = await this.sessionManager.getSession(accessToken);
executionSessionId = session!.id;
@@ -241,7 +244,9 @@ export class SASViyaApiClient {
SYS_JES_JOB_URI: "",
_program: this.rootFolderName + "/" + jobName,
};
let files: any[] = [];
if (data) {
if (JSON.stringify(data).includes(";")) {
files = await this.uploadTables(data, accessToken);
@@ -269,10 +274,12 @@ export class SASViyaApiClient {
arguments: jobArguments,
}),
};
const { result: postedJob, etag } = await this.request<Job>(
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs`,
postJobRequest
);
if (!silent) {
console.log(`Job has been submitted for ${fileName}`);
console.log(
@@ -288,28 +295,33 @@ export class SASViyaApiClient {
accessToken,
silent
);
const { result: currentJob } = await this.request<Job>(
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
{ headers }
);
let jobResult, log;
if (jobStatus === "failed" || jobStatus === "error") {
return Promise.reject(currentJob.error);
}
const resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`;
const logLink = currentJob.links.find((l) => l.rel === "log");
if (resultLink) {
jobResult = await this.request<any>(
`${this.serverUrl}${resultLink}`,
{ headers },
"text"
);
).catch((e) => ({
result: JSON.stringify(e),
}));
}
if (true && logLink) {
log = await this.request<any>(
`${this.serverUrl}${logLink.href}/content`,
`${this.serverUrl}${logLink.href}/content?limit=10000`,
{
headers,
}
@@ -706,11 +718,12 @@ export class SASViyaApiClient {
`The job ${sasJob} was not found in ${this.rootFolderName}`
);
}
let files: any[] = [];
if (data && Object.keys(data).length) {
files = await this.uploadTables(data, accessToken);
}
const jobName = path.basename(sasJob);
const jobFolder = sasJob.replace(`/${jobName}`, "");
const allJobsInFolder = this.rootFolderMap.get(jobFolder.replace("/", ""));
@@ -1005,12 +1018,12 @@ export class SASViyaApiClient {
headers,
};
const { result: file } = await this.request<any>(
const uploadResponse = await this.request<any>(
`${this.serverUrl}/files/files#rawUpload`,
createFileRequest
);
uploadedFiles.push({ tableName, file });
uploadedFiles.push({ tableName, file: uploadResponse.result });
}
return uploadedFiles;
}

View File

@@ -1109,6 +1109,10 @@ export default class SASjs {
return sortedRequests;
}
public clearSasRequests() {
this.sasjsRequests = [];
}
private setupConfiguration() {
if (
this.sasjsConfig.serverUrl === undefined ||

View File

@@ -55,7 +55,8 @@ export async function makeRequest<T>(
);
retryCount = 0;
return retryResponse;
etag = retryResponse.etag;
return retryResponse.result;
} else {
retryCount = 0;
@@ -89,7 +90,8 @@ export async function makeRequest<T>(
);
retryCount = 0;
return retryResponse;
etag = retryResponse.etag;
return retryResponse.result;
} else {
retryCount = 0;