Skip to content

Commit

Permalink
Merge pull request #1063 from github/honeyankit/improve-api-client-lo…
Browse files Browse the repository at this point in the history
…gging

Added more logs to troubleshoot issues faster
  • Loading branch information
honeyankit authored Oct 27, 2023
2 parents 45c6863 + ff32e51 commit 2159f6c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
18 changes: 18 additions & 0 deletions __tests__/api_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ 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...',
status: null
}

mockAxios.get.mockRejectedValue(errorObject)

await expect(api.getJobDetails()).rejects.toThrowError(
new JobDetailsFetchingError(
'fetching job details: unable to get local issuer certificate'
)
)
})

test('get job credentials', async () => {
const apiResponse = {
data: {
Expand Down
18 changes: 14 additions & 4 deletions dist/main/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

32 changes: 24 additions & 8 deletions src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,20 @@ export class ApiClient {
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
const err = error
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 {
throw new JobDetailsFetchingError(
`fetching job details: received code ${err.response
?.status}: ${JSON.stringify(err.response?.data)}`
`fetching job details: ${(error as Error).message}`
)
} else {
throw error
}
}
}
Expand All @@ -89,12 +97,20 @@ export class ApiClient {
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
const err = error
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 {
throw new CredentialFetchingError(
`fetching credentials: received code ${err.response
?.status}: ${JSON.stringify(err.response?.data)}`
`fetching credentials: ${(error as Error).message}`
)
} else {
throw error
}
}
}
Expand Down

0 comments on commit 2159f6c

Please sign in to comment.