From 609d5dae8081d7236aef7b55f82a7933a25379f4 Mon Sep 17 00:00:00 2001 From: Ankit Honey Date: Fri, 20 Oct 2023 05:54:11 +0000 Subject: [PATCH] Fixed the failing test cases --- __tests__/api_client.test.ts | 3 +-- src/api-client.ts | 40 +++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/__tests__/api_client.test.ts b/__tests__/api_client.test.ts index cfea66002..9ef2bbf90 100644 --- a/__tests__/api_client.test.ts +++ b/__tests__/api_client.test.ts @@ -72,7 +72,6 @@ describe('ApiClient', () => { message: 'unable to get local issuer certificate', name: 'Error', stack: 'Error: unable to get local issuer certificate...', - code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY', status: null } @@ -80,7 +79,7 @@ describe('ApiClient', () => { await expect(api.getJobDetails()).rejects.toThrowError( new JobDetailsFetchingError( - 'fetching job details: received code null: {}. Error message: unable to get local issuer certificate' + 'fetching job details: unable to get local issuer certificate' ) ) }) diff --git a/src/api-client.ts b/src/api-client.ts index 648f696ed..b0fc9789d 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -58,16 +58,19 @@ export class ApiClient { } catch (error: unknown) { if (axios.isAxiosError(error)) { const err = error - throw new JobDetailsFetchingError( - `fetching job details: received code ${err.response - ?.status}: ${JSON.stringify(err.response?.data)}. Error message: ${ - err.message - }` - ) + if (err.response) { + throw new JobDetailsFetchingError( + `fetching job details: received code ${err.response + ?.status}: ${JSON.stringify(err.response?.data)}` + ) + } else { + throw new JobDetailsFetchingError( + `fetching job details: ${err.message}` + ) + } } else { - const message = (error as {message?: string}).message throw new JobDetailsFetchingError( - `fetching job details: Error message: ${message}` + `fetching job details: ${(error as Error).message}` ) } } @@ -94,16 +97,19 @@ export class ApiClient { } catch (error: unknown) { if (axios.isAxiosError(error)) { const err = error - throw new CredentialFetchingError( - `fetching credentials: received code ${err.response - ?.status}: ${JSON.stringify(err.response?.data)}. Error message: ${ - err.message - }` - ) + if (err.response) { + throw new CredentialFetchingError( + `fetching credentials: received code ${err.response + ?.status}: ${JSON.stringify(err.response?.data)}` + ) + } else { + throw new CredentialFetchingError( + `fetching credentials: ${err.message}` + ) + } } else { - const message = (error as {message?: string}).message - throw new JobDetailsFetchingError( - `fetching credentials: Error message: ${message}` + throw new CredentialFetchingError( + `fetching credentials: ${(error as Error).message}` ) } }