mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-04 11:10:05 +00:00
fix: update error message when folder not found
This commit is contained in:
@@ -36,6 +36,7 @@ import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
||||
import { RequestClient } from './request/RequestClient'
|
||||
import { prefixMessage } from '@sasjs/utils/error'
|
||||
import * as mime from 'mime'
|
||||
import jwtDecode from 'jwt-decode'
|
||||
|
||||
/**
|
||||
* A client for interfacing with the SAS Viya REST API.
|
||||
@@ -610,7 +611,8 @@ export class SASViyaApiClient {
|
||||
parentFolderPath?: string,
|
||||
parentFolderUri?: string,
|
||||
accessToken?: string,
|
||||
isForced?: boolean
|
||||
isForced?: boolean,
|
||||
serverUrl?: string
|
||||
): Promise<Folder> {
|
||||
const logger = process.logger || console
|
||||
if (!parentFolderPath && !parentFolderUri) {
|
||||
@@ -630,7 +632,17 @@ export class SASViyaApiClient {
|
||||
)
|
||||
const newFolderName = `${parentFolderPath.split('/').pop()}`
|
||||
if (newParentFolderPath === '') {
|
||||
throw new Error('Root folder has to be present on the server.')
|
||||
let error: string = `Root folder ${parentFolderPath} was not found\nPlease check ${serverUrl}/SASDrive\nIf folder DOES exist then it is likely a permission problem\n`
|
||||
if (accessToken) {
|
||||
const tokenResponse: any = jwtDecode(accessToken)
|
||||
const scope = tokenResponse.scope
|
||||
error =
|
||||
error + `The following scopes are contained in client/secret:\n`
|
||||
scope.forEach((element: any) => {
|
||||
error = error + `* ${element}\n`
|
||||
})
|
||||
}
|
||||
throw new Error(error)
|
||||
}
|
||||
logger.info(
|
||||
`Creating parent folder:\n'${newFolderName}' in '${newParentFolderPath}'`
|
||||
@@ -639,7 +651,9 @@ export class SASViyaApiClient {
|
||||
newFolderName,
|
||||
newParentFolderPath,
|
||||
undefined,
|
||||
accessToken
|
||||
accessToken,
|
||||
isForced,
|
||||
serverUrl
|
||||
)
|
||||
logger.info(
|
||||
`Parent folder '${newFolderName}' has been successfully created.`
|
||||
|
||||
22
src/SASjs.ts
22
src/SASjs.ts
@@ -282,21 +282,25 @@ export default class SASjs {
|
||||
parentFolderUri?: string,
|
||||
accessToken?: string,
|
||||
sasApiClient?: SASViyaApiClient,
|
||||
isForced?: boolean
|
||||
isForced?: boolean,
|
||||
serverUrl?: string
|
||||
) {
|
||||
if (sasApiClient)
|
||||
return await sasApiClient.createFolder(
|
||||
folderName,
|
||||
parentFolderPath,
|
||||
parentFolderUri,
|
||||
accessToken
|
||||
accessToken,
|
||||
isForced,
|
||||
serverUrl
|
||||
)
|
||||
return await this.sasViyaApiClient!.createFolder(
|
||||
folderName,
|
||||
parentFolderPath,
|
||||
parentFolderUri,
|
||||
accessToken,
|
||||
isForced
|
||||
isForced,
|
||||
serverUrl
|
||||
)
|
||||
}
|
||||
|
||||
@@ -761,7 +765,8 @@ export default class SASjs {
|
||||
members,
|
||||
accessToken,
|
||||
sasApiClient,
|
||||
isForced
|
||||
isForced,
|
||||
serverUrl
|
||||
)
|
||||
}
|
||||
|
||||
@@ -969,7 +974,8 @@ export default class SASjs {
|
||||
membersJson: any[],
|
||||
accessToken?: string,
|
||||
sasApiClient?: SASViyaApiClient,
|
||||
isForced?: boolean
|
||||
isForced?: boolean,
|
||||
serverUrl?: string
|
||||
) {
|
||||
await asyncForEach(membersJson, async (member: any) => {
|
||||
switch (member.type) {
|
||||
@@ -980,7 +986,8 @@ export default class SASjs {
|
||||
undefined,
|
||||
accessToken,
|
||||
sasApiClient,
|
||||
isForced
|
||||
isForced,
|
||||
serverUrl
|
||||
)
|
||||
break
|
||||
case 'file':
|
||||
@@ -1012,7 +1019,8 @@ export default class SASjs {
|
||||
member.members,
|
||||
accessToken,
|
||||
sasApiClient,
|
||||
isForced
|
||||
isForced,
|
||||
serverUrl
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user