diff --git a/__tests__/api_client.test.ts b/__tests__/api_client.test.ts index 34895f041..cfea66002 100644 --- a/__tests__/api_client.test.ts +++ b/__tests__/api_client.test.ts @@ -66,6 +66,25 @@ describe('ApiClient', () => { ) }) + test('job details with certificate error', async () => { + const errorObject = { + isAxiosError: true, + 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 + } + + mockAxios.get.mockRejectedValue(errorObject) + + await expect(api.getJobDetails()).rejects.toThrowError( + new JobDetailsFetchingError( + 'fetching job details: received code null: {}. Error message: unable to get local issuer certificate' + ) + ) + }) + test('get job credentials', async () => { const apiResponse = { data: { diff --git a/src/api-client.ts b/src/api-client.ts index 0623270b8..648f696ed 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -60,10 +60,15 @@ export class ApiClient { const err = error throw new JobDetailsFetchingError( `fetching job details: received code ${err.response - ?.status}: ${JSON.stringify(err.response?.data)}` + ?.status}: ${JSON.stringify(err.response?.data)}. Error message: ${ + err.message + }` ) } else { - throw error + const message = (error as {message?: string}).message + throw new JobDetailsFetchingError( + `fetching job details: Error message: ${message}` + ) } } } @@ -91,10 +96,15 @@ export class ApiClient { const err = error throw new CredentialFetchingError( `fetching credentials: received code ${err.response - ?.status}: ${JSON.stringify(err.response?.data)}` + ?.status}: ${JSON.stringify(err.response?.data)}. Error message: ${ + err.message + }` ) } else { - throw error + const message = (error as {message?: string}).message + throw new JobDetailsFetchingError( + `fetching credentials: Error message: ${message}` + ) } } }