1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-07 12:30:06 +00:00

fix(refresh-token): improved error message

This commit is contained in:
Yury Shkoda
2022-07-18 14:35:33 +03:00
parent 7b8fb774cc
commit a39faa0f4b
4 changed files with 12 additions and 6 deletions

View File

@@ -28,7 +28,7 @@ export async function refreshTokensForSasjs(
} }
}) })
.catch((err) => { .catch((err) => {
throw prefixMessage(err, 'Error while refreshing tokens') throw prefixMessage(err, 'Error while refreshing tokens: ')
}) })
return authResponse return authResponse

View File

@@ -42,7 +42,7 @@ export async function refreshTokensForViya(
) )
.then((res) => res.result) .then((res) => res.result)
.catch((err) => { .catch((err) => {
throw prefixMessage(err, 'Error while refreshing tokens') throw prefixMessage(err, 'Error while refreshing tokens: ')
}) })
return authResponse return authResponse

View File

@@ -27,17 +27,20 @@ describe('refreshTokensForSasjs', () => {
it('should handle errors while refreshing tokens', async () => { it('should handle errors while refreshing tokens', async () => {
setupMocks() setupMocks()
const refresh_token = generateToken(30) const refresh_token = generateToken(30)
const tokenError = 'unable to verify the first certificate'
jest jest
.spyOn(requestClient, 'post') .spyOn(requestClient, 'post')
.mockImplementation(() => Promise.reject('Token Error')) .mockImplementation(() => Promise.reject(tokenError))
const error = await refreshTokensForSasjs( const error = await refreshTokensForSasjs(
requestClient, requestClient,
refresh_token refresh_token
).catch((e: any) => e) ).catch((e: any) => e)
expect(error).toContain('Error while refreshing tokens') expect(error).toEqual(`Error while refreshing tokens: ${tokenError}`)
}) })
}) })

View File

@@ -46,17 +46,20 @@ describe('refreshTokensForViya', () => {
it('should handle errors while refreshing tokens', async () => { it('should handle errors while refreshing tokens', async () => {
setupMocks() setupMocks()
const access_token = generateToken(30) const access_token = generateToken(30)
const refresh_token = generateToken(30) const refresh_token = generateToken(30)
const tokenError = 'unable to verify the first certificate'
const authConfig: AuthConfig = { const authConfig: AuthConfig = {
access_token, access_token,
refresh_token, refresh_token,
client: 'cl13nt', client: 'cl13nt',
secret: 's3cr3t' secret: 's3cr3t'
} }
jest jest
.spyOn(requestClient, 'post') .spyOn(requestClient, 'post')
.mockImplementation(() => Promise.reject('Token Error')) .mockImplementation(() => Promise.reject(tokenError))
const error = await refreshTokensForViya( const error = await refreshTokensForViya(
requestClient, requestClient,
@@ -65,7 +68,7 @@ describe('refreshTokensForViya', () => {
authConfig.refresh_token authConfig.refresh_token
).catch((e: any) => e) ).catch((e: any) => e)
expect(error).toContain('Error while refreshing tokens') expect(error).toEqual(`Error while refreshing tokens: ${tokenError}`)
}) })
}) })