mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-18 09:30:06 +00:00
fix(root-folder-not-found): create RootFolderNotFoundError class
This commit is contained in:
@@ -6,7 +6,7 @@ GREEN="\033[1;32m"
|
|||||||
# temporary file which holds the message).
|
# temporary file which holds the message).
|
||||||
commit_message=$(cat "$1")
|
commit_message=$(cat "$1")
|
||||||
|
|
||||||
if (echo "$commit_message" | grep -Eq "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z0-9 \-\*]+\))?!?: .+$") then
|
if (echo "$commit_message" | grep -Eq "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z0-9 -\*]+\))?!?: .+$") then
|
||||||
echo "${GREEN} ✔ Commit message meets Conventional Commit standards"
|
echo "${GREEN} ✔ Commit message meets Conventional Commit standards"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { isRelativePath, isUri, isUrl, rootFolderNotFound } from './utils'
|
import { isRelativePath, isUri, isUrl } from './utils'
|
||||||
import * as NodeFormData from 'form-data'
|
import * as NodeFormData from 'form-data'
|
||||||
import {
|
import {
|
||||||
Job,
|
Job,
|
||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
JobDefinition,
|
JobDefinition,
|
||||||
PollOptions
|
PollOptions
|
||||||
} from './types'
|
} from './types'
|
||||||
import { JobExecutionError } from './types/errors'
|
import { JobExecutionError, RootFolderNotFoundError } from './types/errors'
|
||||||
import { SessionManager } from './SessionManager'
|
import { SessionManager } from './SessionManager'
|
||||||
import { ContextManager } from './ContextManager'
|
import { ContextManager } from './ContextManager'
|
||||||
import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
||||||
@@ -381,7 +381,11 @@ export class SASViyaApiClient {
|
|||||||
)
|
)
|
||||||
const newFolderName = `${parentFolderPath.split('/').pop()}`
|
const newFolderName = `${parentFolderPath.split('/').pop()}`
|
||||||
if (newParentFolderPath === '') {
|
if (newParentFolderPath === '') {
|
||||||
rootFolderNotFound(parentFolderPath, this.serverUrl, accessToken)
|
throw new RootFolderNotFoundError(
|
||||||
|
parentFolderPath,
|
||||||
|
this.serverUrl,
|
||||||
|
accessToken
|
||||||
|
)
|
||||||
}
|
}
|
||||||
logger.info(
|
logger.info(
|
||||||
`Creating parent folder:\n'${newFolderName}' in '${newParentFolderPath}'`
|
`Creating parent folder:\n'${newFolderName}' in '${newParentFolderPath}'`
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { rootFolderNotFound } from '../../utils'
|
|
||||||
|
|
||||||
describe('root folder not found', () => {
|
|
||||||
it('when access token is provided, error message should contain scope of accessToken', () => {
|
|
||||||
const token =
|
|
||||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJzY29wZS0xIiwic2NvcGUtMiJdfQ.ktqPL2ulln-8Asa2jSV9QCfDYmQuNk4tNKopxJR5xZs'
|
|
||||||
let error
|
|
||||||
try {
|
|
||||||
rootFolderNotFound('/myProject', 'https://analytium.co.uk', token)
|
|
||||||
} catch (err) {
|
|
||||||
error = err.message
|
|
||||||
}
|
|
||||||
expect(error).toContain('scope-1')
|
|
||||||
expect(error).toContain('scope-2')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
40
src/types/errors/RootFolderNotFoundError.spec.ts
Normal file
40
src/types/errors/RootFolderNotFoundError.spec.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { RootFolderNotFoundError } from './RootFolderNotFoundError'
|
||||||
|
|
||||||
|
describe('RootFolderNotFoundError', () => {
|
||||||
|
it('when access token is provided, error message should contain the scopes in the token', () => {
|
||||||
|
const token =
|
||||||
|
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJzY29wZS0xIiwic2NvcGUtMiJdfQ.ktqPL2ulln-8Asa2jSV9QCfDYmQuNk4tNKopxJR5xZs'
|
||||||
|
|
||||||
|
const error = new RootFolderNotFoundError(
|
||||||
|
'/myProject',
|
||||||
|
'https://analytium.co.uk',
|
||||||
|
token
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(error).toBeInstanceOf(RootFolderNotFoundError)
|
||||||
|
expect(error.message).toContain('scope-1')
|
||||||
|
expect(error.message).toContain('scope-2')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('when access token is not provided, error message should not contain scopes', () => {
|
||||||
|
const error = new RootFolderNotFoundError(
|
||||||
|
'/myProject',
|
||||||
|
'https://analytium.co.uk'
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(error).toBeInstanceOf(RootFolderNotFoundError)
|
||||||
|
expect(error.message).not.toContain(
|
||||||
|
'Your access token contains the following scopes'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should include the folder path and SASDrive URL in the message', () => {
|
||||||
|
const folderPath = '/myProject'
|
||||||
|
const serverUrl = 'https://analytium.co.uk'
|
||||||
|
const error = new RootFolderNotFoundError(folderPath, serverUrl)
|
||||||
|
|
||||||
|
expect(error).toBeInstanceOf(RootFolderNotFoundError)
|
||||||
|
expect(error.message).toContain(folderPath)
|
||||||
|
expect(error.message).toContain(`${serverUrl}/SASDrive`)
|
||||||
|
})
|
||||||
|
})
|
||||||
24
src/types/errors/RootFolderNotFoundError.ts
Normal file
24
src/types/errors/RootFolderNotFoundError.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { decodeToken } from '@sasjs/utils/auth'
|
||||||
|
|
||||||
|
export class RootFolderNotFoundError extends Error {
|
||||||
|
constructor(
|
||||||
|
parentFolderPath: string,
|
||||||
|
serverUrl: string,
|
||||||
|
accessToken?: string
|
||||||
|
) {
|
||||||
|
let message: string =
|
||||||
|
`Root folder ${parentFolderPath} was not found.` +
|
||||||
|
`\nPlease check ${serverUrl}/SASDrive.` +
|
||||||
|
`\nIf the folder DOES exist then it is likely a permission problem.\n`
|
||||||
|
if (accessToken) {
|
||||||
|
const decodedToken = decodeToken(accessToken)
|
||||||
|
let scope = decodedToken.scope
|
||||||
|
scope = scope.map((element) => '* ' + element)
|
||||||
|
message +=
|
||||||
|
`Your access token contains the following scopes:\n` + scope.join('\n')
|
||||||
|
}
|
||||||
|
super(message)
|
||||||
|
this.name = 'RootFolderNotFoundError'
|
||||||
|
Object.setPrototypeOf(this, RootFolderNotFoundError.prototype)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,3 +7,4 @@ export * from './LoginRequiredError'
|
|||||||
export * from './NotFoundError'
|
export * from './NotFoundError'
|
||||||
export * from './ErrorResponse'
|
export * from './ErrorResponse'
|
||||||
export * from './NoSessionStateError'
|
export * from './NoSessionStateError'
|
||||||
|
export * from './RootFolderNotFoundError'
|
||||||
|
|||||||
@@ -15,4 +15,3 @@ export * from './parseWeboutResponse'
|
|||||||
export * from './fetchLogByChunks'
|
export * from './fetchLogByChunks'
|
||||||
export * from './getValidJson'
|
export * from './getValidJson'
|
||||||
export * from './parseViyaDebugResponse'
|
export * from './parseViyaDebugResponse'
|
||||||
export * from './throwError'
|
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
import { DecodedToken, decodeToken } from '@sasjs/utils'
|
|
||||||
|
|
||||||
export const rootFolderNotFound = (
|
|
||||||
parentFolderPath: string,
|
|
||||||
serverUrl: string,
|
|
||||||
accessToken?: string
|
|
||||||
) => {
|
|
||||||
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 decodedToken: DecodedToken = decodeToken(accessToken)
|
|
||||||
let scope = decodedToken.scope
|
|
||||||
scope = scope.map((element) => '* ' + element)
|
|
||||||
error +=
|
|
||||||
`The following scopes are contained in access token:\n` + scope.join('\n')
|
|
||||||
}
|
|
||||||
throw new Error(error)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user