Skip to content

Commit

Permalink
Fixed the failing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
honeyankit committed Oct 20, 2023
1 parent d77be5a commit 609d5da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
3 changes: 1 addition & 2 deletions __tests__/api_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,14 @@ 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
}

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'
'fetching job details: unable to get local issuer certificate'
)
)
})
Expand Down
40 changes: 23 additions & 17 deletions src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
)
}
}
Expand All @@ -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}`
)
}
}
Expand Down

0 comments on commit 609d5da

Please sign in to comment.