mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-15 16:10:06 +00:00
fix(create-folder): improved error message
This commit is contained in:
@@ -29,11 +29,33 @@ describe('SASViyaApiClient', () => {
|
|||||||
jest
|
jest
|
||||||
.spyOn(requestClient, 'get')
|
.spyOn(requestClient, 'get')
|
||||||
.mockImplementation(() => Promise.reject('Not Found'))
|
.mockImplementation(() => Promise.reject('Not Found'))
|
||||||
|
|
||||||
const error = await sasViyaApiClient
|
const error = await sasViyaApiClient
|
||||||
.createFolder('test', '/foo')
|
.createFolder('test', '/foo')
|
||||||
.catch((e: any) => e)
|
.catch((e: any) => e)
|
||||||
|
|
||||||
expect(error).toBeInstanceOf(RootFolderNotFoundError)
|
expect(error).toBeInstanceOf(RootFolderNotFoundError)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should throw an error when ', async () => {
|
||||||
|
const testMessage1 = 'test message 1'
|
||||||
|
const testMessage2 = 'test message 2.'
|
||||||
|
|
||||||
|
jest.spyOn(requestClient, 'post').mockImplementation(() => {
|
||||||
|
return Promise.reject({
|
||||||
|
message: testMessage1,
|
||||||
|
response: { data: { message: testMessage2 }, status: 409 }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const error = await sasViyaApiClient
|
||||||
|
.createFolder('test', '/foo')
|
||||||
|
.catch((e: any) => e)
|
||||||
|
|
||||||
|
const expectedError = `${testMessage1}. ${testMessage2} To override, please set "isForced" to "true".`
|
||||||
|
|
||||||
|
expect(error).toEqual(expectedError)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const setupMocks = () => {
|
const setupMocks = () => {
|
||||||
|
|||||||
@@ -434,8 +434,8 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result: createFolderResponse } =
|
const { result: createFolderResponse } = await this.requestClient
|
||||||
await this.requestClient.post<Folder>(
|
.post<Folder>(
|
||||||
`/folders/folders?parentFolderUri=${parentFolderUri}`,
|
`/folders/folders?parentFolderUri=${parentFolderUri}`,
|
||||||
{
|
{
|
||||||
name: folderName,
|
name: folderName,
|
||||||
@@ -443,12 +443,34 @@ export class SASViyaApiClient {
|
|||||||
},
|
},
|
||||||
accessToken
|
accessToken
|
||||||
)
|
)
|
||||||
|
.catch((err) => {
|
||||||
|
const { message, response } = err
|
||||||
|
|
||||||
|
if (message && response && response.data && response.data.message) {
|
||||||
|
const { status } = response
|
||||||
|
const { message: responseMessage } = response.data
|
||||||
|
const messages = [message, responseMessage].map((mes: string) =>
|
||||||
|
/\.$/.test(mes) ? mes : `${mes}.`
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!isForced && status === 409) {
|
||||||
|
messages.push(`To override, please set "isForced" to "true".`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const errMessage = messages.join(' ')
|
||||||
|
|
||||||
|
throw errMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err
|
||||||
|
})
|
||||||
|
|
||||||
// update folder map with newly created folder.
|
// update folder map with newly created folder.
|
||||||
await this.populateFolderMap(
|
await this.populateFolderMap(
|
||||||
`${parentFolderPath}/${folderName}`,
|
`${parentFolderPath}/${folderName}`,
|
||||||
accessToken
|
accessToken
|
||||||
)
|
)
|
||||||
|
|
||||||
return createFolderResponse
|
return createFolderResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user