@sasjs/adapter 3.10.0 → 3.10.1
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/node/index.js +2 -2
- package/node/types/errors/InvalidCsrfError.d.ts +3 -0
- package/package.json +1 -1
- package/src/job-execution/WebJobExecutor.ts +1 -1
- package/src/request/RequestClient.ts +28 -1
- package/src/types/errors/InvalidCsrfError.ts +9 -0
- package/types/errors/InvalidCsrfError.d.ts +3 -0
package/package.json
CHANGED
|
@@ -172,7 +172,7 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|
|
172
172
|
const resObj = res
|
|
173
173
|
|
|
174
174
|
if (this.serverType === ServerType.Sasjs) {
|
|
175
|
-
if (res.result._webout < 1)
|
|
175
|
+
if (res.result._webout.length < 1)
|
|
176
176
|
throw new JobExecutionError(
|
|
177
177
|
0,
|
|
178
178
|
'Job execution failed',
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
parseSourceCode,
|
|
20
20
|
createAxiosInstance
|
|
21
21
|
} from '../utils'
|
|
22
|
+
import { InvalidCsrfError } from '../types/errors/InvalidCsrfError'
|
|
22
23
|
|
|
23
24
|
export interface HttpClient {
|
|
24
25
|
get<T>(
|
|
@@ -498,6 +499,24 @@ export class RequestClient implements HttpClient {
|
|
|
498
499
|
throw e
|
|
499
500
|
}
|
|
500
501
|
|
|
502
|
+
if (e instanceof InvalidCsrfError) {
|
|
503
|
+
// Fetching root will inject CSRF token in cookie
|
|
504
|
+
await this.httpClient
|
|
505
|
+
.get('/', {
|
|
506
|
+
withCredentials: true
|
|
507
|
+
})
|
|
508
|
+
.catch((err) => {
|
|
509
|
+
throw prefixMessage(err, 'Error while re-fetching CSRF token.')
|
|
510
|
+
})
|
|
511
|
+
|
|
512
|
+
return await callback().catch((err: any) => {
|
|
513
|
+
throw prefixMessage(
|
|
514
|
+
err,
|
|
515
|
+
'Error while executing callback in handleError. '
|
|
516
|
+
)
|
|
517
|
+
})
|
|
518
|
+
}
|
|
519
|
+
|
|
501
520
|
if (response?.status === 403 || response?.status === 449) {
|
|
502
521
|
this.parseAndSetCsrfToken(response)
|
|
503
522
|
|
|
@@ -584,9 +603,17 @@ export class RequestClient implements HttpClient {
|
|
|
584
603
|
export const throwIfError = (response: AxiosResponse) => {
|
|
585
604
|
switch (response.status) {
|
|
586
605
|
case 400:
|
|
587
|
-
if (
|
|
606
|
+
if (
|
|
607
|
+
typeof response.data === 'object' &&
|
|
608
|
+
response.data.error === 'invalid_grant'
|
|
609
|
+
) {
|
|
610
|
+
// In SASVIYA when trying to get access token, if auth code is wrong status code will be 400 so in such case we return login required error.
|
|
588
611
|
throw new LoginRequiredError(response.data)
|
|
589
612
|
}
|
|
613
|
+
|
|
614
|
+
if (response.data.toLowerCase() === 'invalid csrf token!') {
|
|
615
|
+
throw new InvalidCsrfError()
|
|
616
|
+
}
|
|
590
617
|
break
|
|
591
618
|
case 401:
|
|
592
619
|
if (typeof response.data === 'object') {
|