mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-03 18:50:05 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bdcbda54c | ||
|
|
a123392c56 | ||
|
|
719135e366 | ||
|
|
6a3ab7032f | ||
|
|
d818d14cb4 | ||
|
|
599c130395 |
@@ -1,6 +1,6 @@
|
|||||||
import { isUrl } from './utils'
|
import { isUrl } from './utils'
|
||||||
import { UploadFile } from './types/UploadFile'
|
import { UploadFile } from './types/UploadFile'
|
||||||
import { ErrorResponse, LoginRequiredError } from './types'
|
import { ErrorResponse, LoginRequiredError } from './types/errors'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
|
|
||||||
export class FileUploader {
|
export class FileUploader {
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ import {
|
|||||||
Folder,
|
Folder,
|
||||||
EditContextInput,
|
EditContextInput,
|
||||||
JobDefinition,
|
JobDefinition,
|
||||||
PollOptions,
|
PollOptions
|
||||||
ComputeJobExecutionError,
|
|
||||||
JobExecutionError
|
|
||||||
} from './types'
|
} from './types'
|
||||||
|
import {
|
||||||
|
ComputeJobExecutionError,
|
||||||
|
JobExecutionError,
|
||||||
|
NotFoundError
|
||||||
|
} from './types/errors'
|
||||||
import { formatDataForRequest } from './utils/formatDataForRequest'
|
import { formatDataForRequest } from './utils/formatDataForRequest'
|
||||||
import { SessionManager } from './SessionManager'
|
import { SessionManager } from './SessionManager'
|
||||||
import { ContextManager } from './ContextManager'
|
import { ContextManager } from './ContextManager'
|
||||||
@@ -19,7 +22,6 @@ import { timestampToYYYYMMDDHHMMSS } from '@sasjs/utils/time'
|
|||||||
import { Logger, LogLevel } from '@sasjs/utils/logger'
|
import { Logger, LogLevel } from '@sasjs/utils/logger'
|
||||||
import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { NotFoundError } from './types/NotFoundError'
|
|
||||||
import { SasAuthResponse } from '@sasjs/utils/types'
|
import { SasAuthResponse } from '@sasjs/utils/types'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
|
|
||||||
@@ -1082,7 +1084,9 @@ export class SASViyaApiClient {
|
|||||||
.get<string>(
|
.get<string>(
|
||||||
`${this.serverUrl}${stateLink.href}?_action=wait&wait=30`,
|
`${this.serverUrl}${stateLink.href}?_action=wait&wait=30`,
|
||||||
accessToken,
|
accessToken,
|
||||||
'text/plain'
|
'text/plain',
|
||||||
|
{},
|
||||||
|
this.debug
|
||||||
)
|
)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw prefixMessage(err, 'Error while getting job state. ')
|
throw prefixMessage(err, 'Error while getting job state. ')
|
||||||
@@ -1107,7 +1111,9 @@ export class SASViyaApiClient {
|
|||||||
.get<string>(
|
.get<string>(
|
||||||
`${this.serverUrl}${stateLink.href}?_action=wait&wait=30`,
|
`${this.serverUrl}${stateLink.href}?_action=wait&wait=30`,
|
||||||
accessToken,
|
accessToken,
|
||||||
'text/plain'
|
'text/plain',
|
||||||
|
{},
|
||||||
|
this.debug
|
||||||
)
|
)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw prefixMessage(
|
throw prefixMessage(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import SASjs from './SASjs'
|
import SASjs from './SASjs'
|
||||||
export * from './types'
|
export * from './types'
|
||||||
|
export * from './types/errors'
|
||||||
export * from './SASViyaApiClient'
|
export * from './SASViyaApiClient'
|
||||||
export * from './SAS9ApiClient'
|
export * from './SAS9ApiClient'
|
||||||
export default SASjs
|
export default SASjs
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import { ServerType } from '@sasjs/utils/types'
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
import { ErrorResponse } from '..'
|
|
||||||
import { SASViyaApiClient } from '../SASViyaApiClient'
|
import { SASViyaApiClient } from '../SASViyaApiClient'
|
||||||
import { ComputeJobExecutionError, LoginRequiredError } from '../types'
|
import {
|
||||||
|
ErrorResponse,
|
||||||
|
ComputeJobExecutionError,
|
||||||
|
LoginRequiredError
|
||||||
|
} from '../types/errors'
|
||||||
import { BaseJobExecutor } from './JobExecutor'
|
import { BaseJobExecutor } from './JobExecutor'
|
||||||
|
|
||||||
export class ComputeJobExecutor extends BaseJobExecutor {
|
export class ComputeJobExecutor extends BaseJobExecutor {
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import { ServerType } from '@sasjs/utils/types'
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
import { ErrorResponse } from '..'
|
|
||||||
import { SASViyaApiClient } from '../SASViyaApiClient'
|
import { SASViyaApiClient } from '../SASViyaApiClient'
|
||||||
import { JobExecutionError, LoginRequiredError } from '../types'
|
import {
|
||||||
|
ErrorResponse,
|
||||||
|
JobExecutionError,
|
||||||
|
LoginRequiredError
|
||||||
|
} from '../types/errors'
|
||||||
import { BaseJobExecutor } from './JobExecutor'
|
import { BaseJobExecutor } from './JobExecutor'
|
||||||
|
|
||||||
export class JesJobExecutor extends BaseJobExecutor {
|
export class JesJobExecutor extends BaseJobExecutor {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { ServerType } from '@sasjs/utils/types'
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
import { ErrorResponse, JobExecutionError, LoginRequiredError } from '..'
|
import {
|
||||||
|
ErrorResponse,
|
||||||
|
JobExecutionError,
|
||||||
|
LoginRequiredError
|
||||||
|
} from '../types/errors'
|
||||||
import { generateFileUploadForm } from '../file/generateFileUploadForm'
|
import { generateFileUploadForm } from '../file/generateFileUploadForm'
|
||||||
import { generateTableUploadForm } from '../file/generateTableUploadForm'
|
import { generateTableUploadForm } from '../file/generateTableUploadForm'
|
||||||
import { RequestClient } from '../request/RequestClient'
|
import { RequestClient } from '../request/RequestClient'
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
|
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
|
||||||
import { CsrfToken, JobExecutionError } from '..'
|
import { CsrfToken } from '..'
|
||||||
import { isAuthorizeFormRequired, isLogInRequired } from '../auth'
|
import { isAuthorizeFormRequired, isLogInRequired } from '../auth'
|
||||||
import { LoginRequiredError } from '../types'
|
import {
|
||||||
import { AuthorizeError } from '../types/AuthorizeError'
|
AuthorizeError,
|
||||||
import { NotFoundError } from '../types/NotFoundError'
|
LoginRequiredError,
|
||||||
|
NotFoundError,
|
||||||
|
InternalServerError,
|
||||||
|
JobExecutionError
|
||||||
|
} from '../types/errors'
|
||||||
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
|
|
||||||
@@ -73,7 +77,8 @@ export class RequestClient implements HttpClient {
|
|||||||
url: string,
|
url: string,
|
||||||
accessToken: string | undefined,
|
accessToken: string | undefined,
|
||||||
contentType: string = 'application/json',
|
contentType: string = 'application/json',
|
||||||
overrideHeaders: { [key: string]: string | number } = {}
|
overrideHeaders: { [key: string]: string | number } = {},
|
||||||
|
debug: boolean = false
|
||||||
): Promise<{ result: T; etag: string }> {
|
): Promise<{ result: T; etag: string }> {
|
||||||
const headers = {
|
const headers = {
|
||||||
...this.getHeaders(accessToken, contentType),
|
...this.getHeaders(accessToken, contentType),
|
||||||
@@ -97,15 +102,18 @@ export class RequestClient implements HttpClient {
|
|||||||
return this.parseResponse<T>(response)
|
return this.parseResponse<T>(response)
|
||||||
})
|
})
|
||||||
.catch(async (e) => {
|
.catch(async (e) => {
|
||||||
return await this.handleError(e, () =>
|
return await this.handleError(
|
||||||
this.get<T>(url, accessToken, contentType, overrideHeaders).catch(
|
e,
|
||||||
(err) => {
|
() =>
|
||||||
throw prefixMessage(
|
this.get<T>(url, accessToken, contentType, overrideHeaders).catch(
|
||||||
err,
|
(err) => {
|
||||||
'Error while executing handle error callback. '
|
throw prefixMessage(
|
||||||
)
|
err,
|
||||||
}
|
'Error while executing handle error callback. '
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
debug
|
||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
throw prefixMessage(err, 'Error while handling error. ')
|
throw prefixMessage(err, 'Error while handling error. ')
|
||||||
})
|
})
|
||||||
@@ -340,7 +348,11 @@ export class RequestClient implements HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError = async (e: any, callback: any) => {
|
private handleError = async (
|
||||||
|
e: any,
|
||||||
|
callback: any,
|
||||||
|
debug: boolean = false
|
||||||
|
) => {
|
||||||
const response = e.response as AxiosResponse
|
const response = e.response as AxiosResponse
|
||||||
|
|
||||||
if (e instanceof AuthorizeError) {
|
if (e instanceof AuthorizeError) {
|
||||||
@@ -386,10 +398,11 @@ export class RequestClient implements HttpClient {
|
|||||||
throw e
|
throw e
|
||||||
} else if (response?.status === 404) {
|
} else if (response?.status === 404) {
|
||||||
throw new NotFoundError(response.config.url!)
|
throw new NotFoundError(response.config.url!)
|
||||||
|
} else if (response?.status === 502) {
|
||||||
|
if (debug) throw new InternalServerError()
|
||||||
|
else return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[e]`, e)
|
|
||||||
|
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,8 +471,6 @@ const throwIfError = (response: AxiosResponse) => {
|
|||||||
throw new AuthorizeError(response.data.message, authorizeRequestUrl)
|
throw new AuthorizeError(response.data.message, authorizeRequestUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[response]`, response)
|
|
||||||
|
|
||||||
const error = parseError(response.data as string)
|
const error = parseError(response.data as string)
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Job } from './Job'
|
import { Job } from '../Job'
|
||||||
|
|
||||||
export class ComputeJobExecutionError extends Error {
|
export class ComputeJobExecutionError extends Error {
|
||||||
constructor(public job: Job, public log: string) {
|
constructor(public job: Job, public log: string) {
|
||||||
9
src/types/errors/InternalServerError.ts
Normal file
9
src/types/errors/InternalServerError.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export class InternalServerError extends Error {
|
||||||
|
constructor() {
|
||||||
|
super('Error: Internal server error.')
|
||||||
|
|
||||||
|
this.name = 'InternalServerError'
|
||||||
|
|
||||||
|
Object.setPrototypeOf(this, InternalServerError.prototype)
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/types/errors/index.ts
Normal file
7
src/types/errors/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export * from './AuthorizeError'
|
||||||
|
export * from './ComputeJobExecutionError'
|
||||||
|
export * from './InternalServerError'
|
||||||
|
export * from './JobExecutionError'
|
||||||
|
export * from './LoginRequiredError'
|
||||||
|
export * from './NotFoundError'
|
||||||
|
export * from './ErrorResponse'
|
||||||
@@ -1,14 +1,10 @@
|
|||||||
export * from './ComputeJobExecutionError'
|
|
||||||
export * from './Context'
|
export * from './Context'
|
||||||
export * from './CsrfToken'
|
export * from './CsrfToken'
|
||||||
export * from './ErrorResponse'
|
|
||||||
export * from './Folder'
|
export * from './Folder'
|
||||||
export * from './Job'
|
export * from './Job'
|
||||||
export * from './JobExecutionError'
|
|
||||||
export * from './JobDefinition'
|
export * from './JobDefinition'
|
||||||
export * from './JobResult'
|
export * from './JobResult'
|
||||||
export * from './Link'
|
export * from './Link'
|
||||||
export * from './LoginRequiredError'
|
|
||||||
export * from './SASjsConfig'
|
export * from './SASjsConfig'
|
||||||
export * from './SASjsRequest'
|
export * from './SASjsRequest'
|
||||||
export * from './Session'
|
export * from './Session'
|
||||||
|
|||||||
Reference in New Issue
Block a user