@sasjs/adapter 3.7.11 → 3.7.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -2
- package/job-execution/Sas9JobExecutor.d.ts +1 -1
- package/node/index.js +2 -2
- package/node/job-execution/Sas9JobExecutor.d.ts +1 -1
- package/node/types/errors/LoginRequiredError.d.ts +1 -1
- package/package.json +1 -1
- package/src/job-execution/Sas9JobExecutor.ts +22 -28
- package/src/request/RequestClient.ts +12 -2
- package/src/types/errors/LoginRequiredError.ts +6 -2
- package/types/errors/LoginRequiredError.d.ts +1 -1
|
@@ -14,6 +14,6 @@ export declare class Sas9JobExecutor extends BaseJobExecutor {
|
|
|
14
14
|
private requestClient;
|
|
15
15
|
private sas9RequestClient;
|
|
16
16
|
constructor(serverUrl: string, serverType: ServerType, jobsPath: string, requestClient: RequestClient, httpsAgentOptions?: https.AgentOptions);
|
|
17
|
-
execute(sasJob: string, data: any, config: any): Promise<
|
|
17
|
+
execute(sasJob: string, data: any, config: any): Promise<unknown>;
|
|
18
18
|
private getRequestParams;
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -74,38 +74,32 @@ export class Sas9JobExecutor extends BaseJobExecutor {
|
|
|
74
74
|
? 'multipart/form-data; boundary=' + (formData as any)._boundary
|
|
75
75
|
: 'text/plain'
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
apiUrl,
|
|
79
|
-
formData,
|
|
80
|
-
undefined,
|
|
81
|
-
contentType,
|
|
82
|
-
{
|
|
77
|
+
const requestPromise = new Promise((resolve, reject) =>
|
|
78
|
+
this.sas9RequestClient!.post(apiUrl, formData, undefined, contentType, {
|
|
83
79
|
Accept: '*/*',
|
|
84
80
|
Connection: 'Keep-Alive'
|
|
85
|
-
}
|
|
86
|
-
)
|
|
87
|
-
.then((res: any) => {
|
|
88
|
-
let resString = res
|
|
89
|
-
|
|
90
|
-
if (typeof res === 'object') {
|
|
91
|
-
resString = JSON.stringify(res)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
this.requestClient!.appendRequest(resString, sasJob, config.debug)
|
|
95
|
-
|
|
96
|
-
return res
|
|
97
81
|
})
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
82
|
+
.then((res: any) => {
|
|
83
|
+
// appending response to requests array that will be used for requests history reference
|
|
84
|
+
this.requestClient!.appendRequest(res, sasJob, config.debug)
|
|
85
|
+
resolve(res)
|
|
86
|
+
})
|
|
87
|
+
.catch((err: any) => {
|
|
88
|
+
// by default error string is equal to actual error object
|
|
89
|
+
let errString = err
|
|
90
|
+
|
|
91
|
+
// if error object contains non empty result attribute, set result to errString
|
|
92
|
+
if (err.result && err.result !== '') errString = err.result
|
|
93
|
+
// if there's no result but error message, set error message to errString
|
|
94
|
+
else if (err.message) errString = err.message
|
|
95
|
+
|
|
96
|
+
// appending error to requests array that will be used for requests history reference
|
|
97
|
+
this.requestClient!.appendRequest(errString, sasJob, config.debug)
|
|
98
|
+
reject(new ErrorResponse(err?.message, err))
|
|
99
|
+
})
|
|
100
|
+
)
|
|
106
101
|
|
|
107
|
-
|
|
108
|
-
})
|
|
102
|
+
return requestPromise
|
|
109
103
|
}
|
|
110
104
|
|
|
111
105
|
private getRequestParams(config: any): any {
|
|
@@ -557,8 +557,18 @@ export class RequestClient implements HttpClient {
|
|
|
557
557
|
}
|
|
558
558
|
|
|
559
559
|
export const throwIfError = (response: AxiosResponse) => {
|
|
560
|
-
|
|
561
|
-
|
|
560
|
+
switch (response.status) {
|
|
561
|
+
case 400:
|
|
562
|
+
if (typeof response.data === 'object') {
|
|
563
|
+
throw new LoginRequiredError(response.data)
|
|
564
|
+
}
|
|
565
|
+
break
|
|
566
|
+
case 401:
|
|
567
|
+
if (typeof response.data === 'object') {
|
|
568
|
+
throw new LoginRequiredError(response.data)
|
|
569
|
+
} else {
|
|
570
|
+
throw new LoginRequiredError()
|
|
571
|
+
}
|
|
562
572
|
}
|
|
563
573
|
|
|
564
574
|
if (response.data?.entityID?.includes('login')) {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export class LoginRequiredError extends Error {
|
|
2
|
-
constructor() {
|
|
3
|
-
|
|
2
|
+
constructor(details?: any) {
|
|
3
|
+
const message = details
|
|
4
|
+
? JSON.stringify(details, null, 2)
|
|
5
|
+
: 'You must be logged in to access this resource'
|
|
6
|
+
|
|
7
|
+
super(`Auth error: ${message}`)
|
|
4
8
|
this.name = 'LoginRequiredError'
|
|
5
9
|
Object.setPrototypeOf(this, LoginRequiredError.prototype)
|
|
6
10
|
}
|