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}` ) } }