mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-06 04:00:05 +00:00
Compare commits
11 Commits
v3.7.11
...
error-body
| Author | SHA1 | Date | |
|---|---|---|---|
| a54df1e2cb | |||
|
|
804e78cf0c | ||
| f6a621fe46 | |||
| c47d0c9789 | |||
|
|
1ddc71b017 | ||
|
|
3e507885ab | ||
| e92d0d73b5 | |||
| 00a99e752c | |||
|
|
b13f3d2fcb | ||
|
|
495e4b9069 | ||
|
|
2e843e3f36 |
1
docs/CNAME
Normal file
1
docs/CNAME
Normal file
@@ -0,0 +1 @@
|
|||||||
|
adapter.sasjs.io
|
||||||
@@ -74,38 +74,32 @@ export class Sas9JobExecutor extends BaseJobExecutor {
|
|||||||
? 'multipart/form-data; boundary=' + (formData as any)._boundary
|
? 'multipart/form-data; boundary=' + (formData as any)._boundary
|
||||||
: 'text/plain'
|
: 'text/plain'
|
||||||
|
|
||||||
return await this.sas9RequestClient!.post(
|
const requestPromise = new Promise((resolve, reject) =>
|
||||||
apiUrl,
|
this.sas9RequestClient!.post(apiUrl, formData, undefined, contentType, {
|
||||||
formData,
|
|
||||||
undefined,
|
|
||||||
contentType,
|
|
||||||
{
|
|
||||||
Accept: '*/*',
|
Accept: '*/*',
|
||||||
Connection: 'Keep-Alive'
|
Connection: 'Keep-Alive'
|
||||||
}
|
})
|
||||||
|
.then((res: any) => {
|
||||||
|
// appending response to requests array that will be used for requests history reference
|
||||||
|
this.requestClient!.appendRequest(res, sasJob, config.debug)
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
|
.catch((err: any) => {
|
||||||
|
// by default error string is equal to actual error object
|
||||||
|
let errString = err
|
||||||
|
|
||||||
|
// if error object contains non empty result attribute, set result to errString
|
||||||
|
if (err.result && err.result !== '') errString = err.result
|
||||||
|
// if there's no result but error message, set error message to errString
|
||||||
|
else if (err.message) errString = err.message
|
||||||
|
|
||||||
|
// appending error to requests array that will be used for requests history reference
|
||||||
|
this.requestClient!.appendRequest(errString, sasJob, config.debug)
|
||||||
|
reject(new ErrorResponse(err?.message, err))
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.then((res: any) => {
|
|
||||||
let resString = res
|
|
||||||
|
|
||||||
if (typeof res === 'object') {
|
return requestPromise
|
||||||
resString = JSON.stringify(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.requestClient!.appendRequest(resString, sasJob, config.debug)
|
|
||||||
|
|
||||||
return res
|
|
||||||
})
|
|
||||||
.catch((err: any) => {
|
|
||||||
let errString = err
|
|
||||||
|
|
||||||
if (typeof err === 'object') {
|
|
||||||
errString = JSON.stringify(errString)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.requestClient!.appendRequest(errString, sasJob, config.debug)
|
|
||||||
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRequestParams(config: any): any {
|
private getRequestParams(config: any): any {
|
||||||
|
|||||||
@@ -557,8 +557,18 @@ export class RequestClient implements HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const throwIfError = (response: AxiosResponse) => {
|
export const throwIfError = (response: AxiosResponse) => {
|
||||||
if (response.status === 401) {
|
switch (response.status) {
|
||||||
throw new LoginRequiredError()
|
case 400:
|
||||||
|
if (typeof response.data === 'object') {
|
||||||
|
throw new LoginRequiredError(response.data)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 401:
|
||||||
|
if (typeof response.data === 'object') {
|
||||||
|
throw new LoginRequiredError(response.data)
|
||||||
|
} else {
|
||||||
|
throw new LoginRequiredError()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.data?.entityID?.includes('login')) {
|
if (response.data?.entityID?.includes('login')) {
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ const ERROR_MESSAGES = {
|
|||||||
CCA: 'unable to verify the first certificate'
|
CCA: 'unable to verify the first certificate'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const incorrectAuthCodeErr = {
|
||||||
|
error: 'unauthorized',
|
||||||
|
error_description: 'Bad credentials'
|
||||||
|
}
|
||||||
|
|
||||||
describe('RequestClient', () => {
|
describe('RequestClient', () => {
|
||||||
let server: http.Server
|
let server: http.Server
|
||||||
|
|
||||||
@@ -65,7 +70,7 @@ describe('RequestClient', () => {
|
|||||||
adapter.getAccessToken('clientId', 'clientSecret', 'incorrect')
|
adapter.getAccessToken('clientId', 'clientSecret', 'incorrect')
|
||||||
).rejects.toEqual(
|
).rejects.toEqual(
|
||||||
prefixMessage(
|
prefixMessage(
|
||||||
new LoginRequiredError(),
|
new LoginRequiredError(incorrectAuthCodeErr),
|
||||||
'Error while getting access token. '
|
'Error while getting access token. '
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -246,7 +251,7 @@ describe('RequestClient - Self Signed Server', () => {
|
|||||||
adapter.getAccessToken('clientId', 'clientSecret', 'incorrect')
|
adapter.getAccessToken('clientId', 'clientSecret', 'incorrect')
|
||||||
).rejects.toEqual(
|
).rejects.toEqual(
|
||||||
prefixMessage(
|
prefixMessage(
|
||||||
new LoginRequiredError(),
|
new LoginRequiredError(incorrectAuthCodeErr),
|
||||||
'Error while getting access token. '
|
'Error while getting access token. '
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export class ErrorResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ErrorBody {
|
export interface ErrorBody {
|
||||||
message: string
|
message: string
|
||||||
details: string
|
details: string
|
||||||
raw: any
|
raw: any
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
export class LoginRequiredError extends Error {
|
export class LoginRequiredError extends Error {
|
||||||
constructor() {
|
constructor(details?: any) {
|
||||||
super('Auth error: You must be logged in to access this resource')
|
const message = details
|
||||||
|
? JSON.stringify(details, null, 2)
|
||||||
|
: 'You must be logged in to access this resource'
|
||||||
|
|
||||||
|
super(`Auth error: ${message}`)
|
||||||
this.name = 'LoginRequiredError'
|
this.name = 'LoginRequiredError'
|
||||||
Object.setPrototypeOf(this, LoginRequiredError.prototype)
|
Object.setPrototypeOf(this, LoginRequiredError.prototype)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,3 +11,4 @@ export * from './RootFolderNotFoundError'
|
|||||||
export * from './JsonParseArrayError'
|
export * from './JsonParseArrayError'
|
||||||
export * from './WeboutResponseError'
|
export * from './WeboutResponseError'
|
||||||
export * from './InvalidJsonError'
|
export * from './InvalidJsonError'
|
||||||
|
export * from './ErrorResponse'
|
||||||
|
|||||||
Reference in New Issue
Block a user