diff --git a/src/SASViyaApiClient.ts b/src/SASViyaApiClient.ts index b336b47..643bf74 100644 --- a/src/SASViyaApiClient.ts +++ b/src/SASViyaApiClient.ts @@ -11,7 +11,11 @@ import { JobDefinition, PollOptions } from './types' -import { JobExecutionError, RootFolderNotFoundError } from './types/errors' +import { + CertificateError, + JobExecutionError, + RootFolderNotFoundError +} from './types/errors' import { SessionManager } from './SessionManager' import { ContextManager } from './ContextManager' import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types' @@ -878,7 +882,8 @@ export class SASViyaApiClient { const { result: folder } = await this.requestClient .get(`${this.serverUrl}${url}`, accessToken) - .catch(() => { + .catch((err) => { + if (err instanceof CertificateError) throw err return { result: null } }) @@ -899,7 +904,8 @@ export class SASViyaApiClient { const { result: folder } = await this.requestClient .get(`${this.serverUrl}${url}`, accessToken) - .catch(() => { + .catch((err) => { + if (err instanceof CertificateError) throw err return { result: null } }) diff --git a/src/auth/getAccessTokenForViya.ts b/src/auth/getAccessTokenForViya.ts index dd4993d..508c767 100644 --- a/src/auth/getAccessTokenForViya.ts +++ b/src/auth/getAccessTokenForViya.ts @@ -1,6 +1,7 @@ import { SasAuthResponse } from '@sasjs/utils/types' import { prefixMessage } from '@sasjs/utils/error' import { RequestClient } from '../request/RequestClient' +import { CertificateError } from '../types/errors' /** * Exchanges the auth code for an access token for the given client. @@ -36,6 +37,7 @@ export async function getAccessTokenForViya( .post(url, data, undefined, 'application/x-www-form-urlencoded', headers) .then((res) => res.result as SasAuthResponse) .catch((err) => { + if (err instanceof CertificateError) throw err throw prefixMessage(err, 'Error while getting access token. ') }) diff --git a/src/request/RequestClient.ts b/src/request/RequestClient.ts index 04ac98d..87bcee1 100644 --- a/src/request/RequestClient.ts +++ b/src/request/RequestClient.ts @@ -7,7 +7,8 @@ import { LoginRequiredError, NotFoundError, InternalServerError, - JobExecutionError + JobExecutionError, + CertificateError } from '../types/errors' import { SASjsRequest } from '../types' import { parseWeboutResponse } from '../utils/parseWeboutResponse' @@ -517,6 +518,10 @@ export class RequestClient implements HttpClient { else return } + if (e.isAxiosError && e.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') { + throw new CertificateError(e.message) + } + if (e.message) throw e else throw prefixMessage(e, 'Error while handling error. ') } diff --git a/src/types/errors/CertificateError.ts b/src/types/errors/CertificateError.ts new file mode 100644 index 0000000..ef08278 --- /dev/null +++ b/src/types/errors/CertificateError.ts @@ -0,0 +1,12 @@ +const instructionsToFix = + 'https://github.com/sasjs/cli/issues/1181#issuecomment-1090638584' + +export class CertificateError extends Error { + constructor(message: string) { + super( + `Error: ${message}\nPlease visit below link to resolve this issue:\n- ${instructionsToFix}\n` + ) + this.name = 'CertificateError' + Object.setPrototypeOf(this, CertificateError.prototype) + } +} diff --git a/src/types/errors/index.ts b/src/types/errors/index.ts index e2b0766..7bd386b 100644 --- a/src/types/errors/index.ts +++ b/src/types/errors/index.ts @@ -1,13 +1,14 @@ export * from './AuthorizeError' +export * from './CertificateError' export * from './ComputeJobExecutionError' +export * from './ErrorResponse' export * from './InternalServerError' +export * from './InvalidJsonError' export * from './JobExecutionError' export * from './JobStatePollError' -export * from './LoginRequiredError' -export * from './NotFoundError' -export * from './ErrorResponse' -export * from './NoSessionStateError' -export * from './RootFolderNotFoundError' export * from './JsonParseArrayError' +export * from './LoginRequiredError' +export * from './NoSessionStateError' +export * from './NotFoundError' +export * from './RootFolderNotFoundError' export * from './WeboutResponseError' -export * from './InvalidJsonError'