mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-06 20:10:05 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
927bb8c78c | ||
|
|
509171c484 | ||
|
|
ae98b50a21 | ||
|
|
939e6803e1 | ||
|
|
6a055a4fc6 | ||
|
|
970e14b2e1 | ||
|
|
4c9e48550e | ||
|
|
8504ec6c4d | ||
|
|
a0ad8b3f34 | ||
|
|
53990a9ba3 |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
232
docs/classes/reflection-724.reflection-187.fileuploader.html
Normal file
232
docs/classes/reflection-724.reflection-187.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
313
docs/classes/reflection-724.reflection-187.sas9apiclient.html
Normal file
313
docs/classes/reflection-724.reflection-187.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1337
docs/classes/reflection-724.reflection-187.sasjs.html
Normal file
1337
docs/classes/reflection-724.reflection-187.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1265
docs/classes/reflection-724.reflection-187.sasviyaapiclient.html
Normal file
1265
docs/classes/reflection-724.reflection-187.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
272
docs/classes/reflection-724.reflection-187.sessionmanager.html
Normal file
272
docs/classes/reflection-724.reflection-187.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
231
docs/classes/types.errorresponse.html
Normal file
231
docs/classes/types.errorresponse.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
107
docs/modules/reflection-724.html
Normal file
107
docs/modules/reflection-724.html
Normal file
File diff suppressed because one or more lines are too long
129
docs/modules/reflection-724.reflection-187.html
Normal file
129
docs/modules/reflection-724.reflection-187.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -323,17 +323,14 @@ export class SASViyaApiClient {
|
|||||||
{
|
{
|
||||||
headers
|
headers
|
||||||
}
|
}
|
||||||
).catch((e) => {
|
).catch((err) => {
|
||||||
console.error(e)
|
if (err && err.status === 404) {
|
||||||
|
|
||||||
if (e && e.status === 404) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The context '${contextName}' was not found on this server.`
|
`The context '${contextName}' was not found on this server.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
throw new Error(
|
|
||||||
`An error occurred when fetching the context '${contextName}'.`
|
throw err
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// An If-Match header with the value of the last ETag for the context
|
// An If-Match header with the value of the last ETag for the context
|
||||||
@@ -1388,12 +1385,8 @@ export class SASViyaApiClient {
|
|||||||
const { result: contexts } = await this.request<{ items: Context[] }>(
|
const { result: contexts } = await this.request<{ items: Context[] }>(
|
||||||
`${this.serverUrl}/compute/contexts?filter=eq(name, "${contextName}")`,
|
`${this.serverUrl}/compute/contexts?filter=eq(name, "${contextName}")`,
|
||||||
{ headers }
|
{ headers }
|
||||||
).catch((e) => {
|
).catch((err) => {
|
||||||
console.error(e)
|
throw err
|
||||||
|
|
||||||
throw new Error(
|
|
||||||
`An error occurred when fetching the context '${contextName}'.`
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!contexts || !(contexts.items && contexts.items.length)) {
|
if (!contexts || !(contexts.items && contexts.items.length)) {
|
||||||
|
|||||||
56
src/SASjs.ts
56
src/SASjs.ts
@@ -30,7 +30,8 @@ import {
|
|||||||
ServerType,
|
ServerType,
|
||||||
CsrfToken,
|
CsrfToken,
|
||||||
UploadFile,
|
UploadFile,
|
||||||
EditContextInput
|
EditContextInput,
|
||||||
|
ErrorResponse
|
||||||
} from './types'
|
} from './types'
|
||||||
import { SASViyaApiClient } from './SASViyaApiClient'
|
import { SASViyaApiClient } from './SASViyaApiClient'
|
||||||
import { SAS9ApiClient } from './SAS9ApiClient'
|
import { SAS9ApiClient } from './SAS9ApiClient'
|
||||||
@@ -668,7 +669,9 @@ export default class SASjs {
|
|||||||
resolve(retryResponse)
|
resolve(retryResponse)
|
||||||
} else {
|
} else {
|
||||||
this.retryCountComputeApi = 0
|
this.retryCountComputeApi = 0
|
||||||
reject({ MESSAGE: 'Compute API retry requests limit reached.' })
|
reject(
|
||||||
|
new ErrorResponse('Compute API retry requests limit reached')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,7 +682,7 @@ export default class SASjs {
|
|||||||
sasjsWaitingRequest.config = config
|
sasjsWaitingRequest.config = config
|
||||||
this.sasjsWaitingRequests.push(sasjsWaitingRequest)
|
this.sasjsWaitingRequests.push(sasjsWaitingRequest)
|
||||||
} else {
|
} else {
|
||||||
reject({ MESSAGE: error || 'Job execution failed.' })
|
reject(new ErrorResponse('Job execution failed', error))
|
||||||
}
|
}
|
||||||
|
|
||||||
this.appendSasjsRequest(response.log, sasJob, null)
|
this.appendSasjsRequest(response.log, sasJob, null)
|
||||||
@@ -761,11 +764,13 @@ export default class SASjs {
|
|||||||
resolve(retryResponse)
|
resolve(retryResponse)
|
||||||
} else {
|
} else {
|
||||||
this.retryCountJeseApi = 0
|
this.retryCountJeseApi = 0
|
||||||
reject({ MESSAGE: 'JES API retry requests limit reached' })
|
reject(
|
||||||
|
new ErrorResponse('Jes API retry requests limit reached')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reject({ MESSAGE: (e && e.message) || 'Job execution failed.' })
|
reject(new ErrorResponse('Job execution failed', e))
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -877,7 +882,7 @@ export default class SASjs {
|
|||||||
sasjsWaitingRequest.requestPromise.promise = new Promise(
|
sasjsWaitingRequest.requestPromise.promise = new Promise(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
if (isError) {
|
if (isError) {
|
||||||
reject({ MESSAGE: errorMsg })
|
reject(new ErrorResponse(errorMsg))
|
||||||
}
|
}
|
||||||
const headers: any = {}
|
const headers: any = {}
|
||||||
if (this.csrfTokenWeb) {
|
if (this.csrfTokenWeb) {
|
||||||
@@ -943,9 +948,12 @@ export default class SASjs {
|
|||||||
if (jsonResponseText !== '') {
|
if (jsonResponseText !== '') {
|
||||||
resolve(JSON.parse(jsonResponseText))
|
resolve(JSON.parse(jsonResponseText))
|
||||||
} else {
|
} else {
|
||||||
reject({
|
reject(
|
||||||
MESSAGE: this.parseSAS9ErrorResponse(responseText)
|
new ErrorResponse(
|
||||||
})
|
'Job WEB execution failed',
|
||||||
|
this.parseSAS9ErrorResponse(responseText)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
config.serverType === ServerType.SASViya &&
|
config.serverType === ServerType.SASViya &&
|
||||||
@@ -958,15 +966,30 @@ export default class SASjs {
|
|||||||
try {
|
try {
|
||||||
resolve(JSON.parse(resText))
|
resolve(JSON.parse(resText))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject({ MESSAGE: resText })
|
reject(
|
||||||
|
new ErrorResponse(
|
||||||
|
'Job WEB debug response parsing failed',
|
||||||
|
{ response: resText, exception: e }
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(err: any) => {
|
(err: any) => {
|
||||||
reject({ MESSAGE: err })
|
reject(
|
||||||
|
new ErrorResponse(
|
||||||
|
'Job WEB debug response parsing failed',
|
||||||
|
err
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject({ MESSAGE: responseText })
|
reject(
|
||||||
|
new ErrorResponse(
|
||||||
|
'Job WEB debug response parsing failed',
|
||||||
|
{ response: responseText, exception: e }
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.updateUsername(responseText)
|
this.updateUsername(responseText)
|
||||||
@@ -974,14 +997,19 @@ export default class SASjs {
|
|||||||
const parsedJson = JSON.parse(responseText)
|
const parsedJson = JSON.parse(responseText)
|
||||||
resolve(parsedJson)
|
resolve(parsedJson)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject({ MESSAGE: responseText })
|
reject(
|
||||||
|
new ErrorResponse('Job WEB response parsing failed', {
|
||||||
|
response: responseText,
|
||||||
|
exception: e
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((e: Error) => {
|
.catch((e: Error) => {
|
||||||
reject(e)
|
reject(new ErrorResponse('Job WEB request failed', e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
26
src/types/ErrorResponse.ts
Normal file
26
src/types/ErrorResponse.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
export class ErrorResponse {
|
||||||
|
body: ErrorBody
|
||||||
|
|
||||||
|
constructor(message: string, details?: any) {
|
||||||
|
let detailsString = ''
|
||||||
|
let raw
|
||||||
|
|
||||||
|
try {
|
||||||
|
detailsString = JSON.stringify(details)
|
||||||
|
} catch {
|
||||||
|
raw = details
|
||||||
|
}
|
||||||
|
|
||||||
|
this.body = {
|
||||||
|
message,
|
||||||
|
details: detailsString,
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ErrorBody {
|
||||||
|
message: string
|
||||||
|
details: string
|
||||||
|
raw: any
|
||||||
|
}
|
||||||
@@ -9,3 +9,4 @@ export * from './SASjsWaitingRequest'
|
|||||||
export * from './ServerType'
|
export * from './ServerType'
|
||||||
export * from './Session'
|
export * from './Session'
|
||||||
export * from './UploadFile'
|
export * from './UploadFile'
|
||||||
|
export * from './ErrorResponse'
|
||||||
|
|||||||
@@ -37,13 +37,28 @@ export async function makeRequest<T>(
|
|||||||
...request,
|
...request,
|
||||||
headers: { ...request.headers, [tokenHeader]: token }
|
headers: { ...request.headers, [tokenHeader]: token }
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch(url, retryRequest).then((res) => {
|
return fetch(url, retryRequest).then((res) => {
|
||||||
etag = res.headers.get('ETag')
|
etag = res.headers.get('ETag')
|
||||||
return responseTransform(res)
|
return responseTransform(res)
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
let body: any = await response.text()
|
||||||
|
|
||||||
|
try {
|
||||||
|
body = JSON.parse(body)
|
||||||
|
|
||||||
|
body.message = `Forbidden. Check your permissions and user groups. ${
|
||||||
|
body.message || ''
|
||||||
|
}`
|
||||||
|
|
||||||
|
body = JSON.stringify(body)
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
return Promise.reject({ status: response.status, body })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const body = await response.text()
|
let body: any = await response.text()
|
||||||
|
|
||||||
if (needsRetry(body)) {
|
if (needsRetry(body)) {
|
||||||
if (retryCount < retryLimit) {
|
if (retryCount < retryLimit) {
|
||||||
@@ -65,6 +80,18 @@ export async function makeRequest<T>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response.status === 401) {
|
||||||
|
try {
|
||||||
|
body = JSON.parse(body)
|
||||||
|
|
||||||
|
body.message = `Unauthorized request. Check your credentials(client, secret, access token). ${
|
||||||
|
body.message || ''
|
||||||
|
}`
|
||||||
|
|
||||||
|
body = JSON.stringify(body)
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.reject({ status: response.status, body })
|
return Promise.reject({ status: response.status, body })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -104,5 +131,6 @@ export async function makeRequest<T>(
|
|||||||
return responseTransformed
|
return responseTransformed
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return { result, etag }
|
return { result, etag }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user