From a39faa0f4b625115a028dcccbdc43d07620d9822 Mon Sep 17 00:00:00 2001 From: Yury Shkoda Date: Mon, 18 Jul 2022 14:35:33 +0300 Subject: [PATCH] fix(refresh-token): improved error message --- src/auth/refreshTokensForSasjs.ts | 2 +- src/auth/refreshTokensForViya.ts | 2 +- src/auth/spec/refreshTokensForSasjs.spec.ts | 7 +++++-- src/auth/spec/refreshTokensForViya.spec.ts | 7 +++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/auth/refreshTokensForSasjs.ts b/src/auth/refreshTokensForSasjs.ts index e6ed601..bf4818c 100644 --- a/src/auth/refreshTokensForSasjs.ts +++ b/src/auth/refreshTokensForSasjs.ts @@ -28,7 +28,7 @@ export async function refreshTokensForSasjs( } }) .catch((err) => { - throw prefixMessage(err, 'Error while refreshing tokens') + throw prefixMessage(err, 'Error while refreshing tokens: ') }) return authResponse diff --git a/src/auth/refreshTokensForViya.ts b/src/auth/refreshTokensForViya.ts index 0826bc8..e10d15c 100644 --- a/src/auth/refreshTokensForViya.ts +++ b/src/auth/refreshTokensForViya.ts @@ -42,7 +42,7 @@ export async function refreshTokensForViya( ) .then((res) => res.result) .catch((err) => { - throw prefixMessage(err, 'Error while refreshing tokens') + throw prefixMessage(err, 'Error while refreshing tokens: ') }) return authResponse diff --git a/src/auth/spec/refreshTokensForSasjs.spec.ts b/src/auth/spec/refreshTokensForSasjs.spec.ts index 8148c0f..0a8a49f 100644 --- a/src/auth/spec/refreshTokensForSasjs.spec.ts +++ b/src/auth/spec/refreshTokensForSasjs.spec.ts @@ -27,17 +27,20 @@ describe('refreshTokensForSasjs', () => { it('should handle errors while refreshing tokens', async () => { setupMocks() + const refresh_token = generateToken(30) + const tokenError = 'unable to verify the first certificate' + jest .spyOn(requestClient, 'post') - .mockImplementation(() => Promise.reject('Token Error')) + .mockImplementation(() => Promise.reject(tokenError)) const error = await refreshTokensForSasjs( requestClient, refresh_token ).catch((e: any) => e) - expect(error).toContain('Error while refreshing tokens') + expect(error).toEqual(`Error while refreshing tokens: ${tokenError}`) }) }) diff --git a/src/auth/spec/refreshTokensForViya.spec.ts b/src/auth/spec/refreshTokensForViya.spec.ts index ef8fe95..49b8f19 100644 --- a/src/auth/spec/refreshTokensForViya.spec.ts +++ b/src/auth/spec/refreshTokensForViya.spec.ts @@ -46,17 +46,20 @@ describe('refreshTokensForViya', () => { it('should handle errors while refreshing tokens', async () => { setupMocks() + const access_token = generateToken(30) const refresh_token = generateToken(30) + const tokenError = 'unable to verify the first certificate' const authConfig: AuthConfig = { access_token, refresh_token, client: 'cl13nt', secret: 's3cr3t' } + jest .spyOn(requestClient, 'post') - .mockImplementation(() => Promise.reject('Token Error')) + .mockImplementation(() => Promise.reject(tokenError)) const error = await refreshTokensForViya( requestClient, @@ -65,7 +68,7 @@ describe('refreshTokensForViya', () => { authConfig.refresh_token ).catch((e: any) => e) - expect(error).toContain('Error while refreshing tokens') + expect(error).toEqual(`Error while refreshing tokens: ${tokenError}`) }) })