Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update api error handling #108

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/views/commits/CommitHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
repositorySetting.getUrl()
}}</span
>.<br />
The repository does not exist or not visible with provided pesonal access token.
{{ failedMessage }}
</div>

<LoadingImage :loading="loading" @cancel="loading = false" />
Expand Down Expand Up @@ -79,6 +79,7 @@ export default defineComponent({
const loading = ref(false)

const isFailed = ref(false)
const failedMessage = ref('')
const getCommits = async (): Promise<void> => {
loading.value = true
const { repositorySetting } = props
Expand All @@ -88,7 +89,8 @@ export default defineComponent({
.then((ch: CommitHistory) => mutations.replace(ch))
.then(() => false)
.catch((e: Error) => {
logger.error(e)
logger.error(e.cause as Error)
failedMessage.value = e.message
return true
})
.finally(() => {
Expand All @@ -103,6 +105,7 @@ export default defineComponent({
clearCommits,
getCommits,
isFailed,
failedMessage,
openCommitsUrl,
commits,
loading,
Expand Down
7 changes: 5 additions & 2 deletions src/views/issues/GitHubIssue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
repositorySetting.getUrl()
}}</span
>.<br />
The repository does not exist or not visible with provided pesonal access token.
{{ failedMessage }}
</div>

<LoadingImage :loading="loading" @cancel="loading = false" />
Expand Down Expand Up @@ -88,6 +88,7 @@ export default defineComponent({

const queryState = ref('')
const isFailed = ref(false)
const failedMessage = ref('')
const getIssues = async (): Promise<void> => {
loading.value = true
const { repositorySetting } = props
Expand All @@ -98,7 +99,8 @@ export default defineComponent({
.then((i: Issues) => mutations.replace(i))
.then(() => false)
.catch((e: Error) => {
logger.error(e)
logger.error(e.cause as Error)
failedMessage.value = e.message
return true
})
.finally(() => {
Expand All @@ -123,6 +125,7 @@ export default defineComponent({
getIssues,
queryState,
isFailed,
failedMessage,
openIssueUrl,
issues,
loading,
Expand Down
7 changes: 5 additions & 2 deletions src/views/pullrequests/GitHubPullRequest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
repositorySetting.getUrl()
}}</span
>.<br />
The repository does not exist or not visible with provided pesonal access token.
{{ failedMessage }}
</div>

<LoadingImage :loading="loading" @cancel="loading = false" />
Expand Down Expand Up @@ -92,6 +92,7 @@ export default defineComponent({

const queryState = ref('')
const isFailed = ref(false)
const failedMessage = ref('')
const getPullRequests = async (): Promise<void> => {
loading.value = true
const { repositorySetting } = props
Expand All @@ -102,7 +103,8 @@ export default defineComponent({
.then((prs: PullRequests) => mutations.replace(prs))
.then(() => false)
.catch((e: Error) => {
logger.error(e)
logger.error(e.cause as Error)
failedMessage.value = e.message
return true
})
.finally(() => {
Expand All @@ -127,6 +129,7 @@ export default defineComponent({
getPullRequests,
queryState,
isFailed,
failedMessage,
openPullRequestUrl,
pullRequests,
loading,
Expand Down
7 changes: 5 additions & 2 deletions src/views/releases/GitHubRelease.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
repositorySetting.getUrl()
}}</span
>.<br />
The repository does not exist or not visible with provided pesonal access token.
{{ failedMessage }}
</div>

<LoadingImage :loading="loading" @cancel="loading = false" />
Expand Down Expand Up @@ -91,6 +91,7 @@ export default defineComponent({
const loading = ref(false)

const isFailed = ref(false)
const failedMessage = ref('')
const getReleases = async (): Promise<void> => {
loading.value = true
const { repositorySetting } = props
Expand All @@ -100,7 +101,8 @@ export default defineComponent({
.then((r: Releases) => mutations.replace(r))
.then(() => false)
.catch((e: Error) => {
logger.error(e)
logger.error(e.cause as Error)
failedMessage.value = e.message
return true
})
.finally(() => {
Expand All @@ -124,6 +126,7 @@ export default defineComponent({
clearReleases,
getReleases,
isFailed,
failedMessage,
openReleaseUrl,
releases,
loading,
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/views/commits/CommitHistory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GitHubAccessError } from '@/application/domain/interface/githubAccessor'
import {
Account,
Commit,
Expand Down Expand Up @@ -122,7 +123,8 @@ describe('CommitHistory.vue', () => {
})

it('fails to get commits', async () => {
const err = new Error('error')
const cause = new Error('cause')
const err = new GitHubAccessError('error', { cause: cause })
const supplier = () => {
throw err
}
Expand Down Expand Up @@ -150,7 +152,7 @@ describe('CommitHistory.vue', () => {
.then(() => nextTick())

// then: error mock is called
expect(errorMock).toHaveBeenCalledWith(err)
expect(errorMock).toHaveBeenCalledWith(cause)
})

it('opens commits url (repository name)', async () => {
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/views/issues/GitHubIssue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GitHubAccessError } from '@/application/domain/interface/githubAccessor'
import { Account, GitHubUrl, Issue, Issues } from '@/application/domain/model/github'
import { RepositorySetting } from '@/application/domain/model/githubRepository'
import { GetIssuesUseCase, GetIssuesUseCaseFactory } from '@/application/usecase/githubRepository'
Expand Down Expand Up @@ -158,7 +159,8 @@ describe('GitHubIssue.vue', () => {
})

it('fails to get issues', async () => {
const err = new Error('error')
const cause = new Error('cause')
const err = new GitHubAccessError('error', { cause: cause })
const supplier = () => {
throw err
}
Expand All @@ -185,7 +187,7 @@ describe('GitHubIssue.vue', () => {
.then(() => nextTick())

// then: error mock is called
expect(errorMock).toHaveBeenCalledWith(err)
expect(errorMock).toHaveBeenCalledWith(cause)
})

it('opens issues url (repository name)', async () => {
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/views/pullrequests/GitHubPullRequest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GitHubAccessError } from '@/application/domain/interface/githubAccessor'
import {
Account,
GitHubUrl,
Expand Down Expand Up @@ -181,7 +182,8 @@ describe('GitHubPullRequest.vue', () => {
})

it('fails to get PRs', async () => {
const err = new Error('error')
const cause = new Error('cause')
const err = new GitHubAccessError('error', { cause: cause })
const supplier = () => {
throw err
}
Expand All @@ -208,7 +210,7 @@ describe('GitHubPullRequest.vue', () => {
.then(() => nextTick())

// then: error mock is called
expect(errorMock).toHaveBeenCalledWith(err)
expect(errorMock).toHaveBeenCalledWith(cause)
})

it('opens pull requests url (repository name)', async () => {
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/views/releases/GitHubRelease.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GitHubAccessError } from '@/application/domain/interface/githubAccessor'
import { Account, GitHubUrl, Release, Releases } from '@/application/domain/model/github'
import { RepositorySetting } from '@/application/domain/model/githubRepository'
import {
Expand Down Expand Up @@ -146,7 +147,8 @@ describe('GitHubRelease.vue', () => {
})

it('fails to get releases', async () => {
const err = new Error('error')
const cause = new Error('cause')
const err = new GitHubAccessError('error', { cause: cause })
const supplier = () => {
throw err
}
Expand Down Expand Up @@ -174,7 +176,7 @@ describe('GitHubRelease.vue', () => {
.then(() => nextTick())

// then: error mock is called
expect(errorMock).toHaveBeenCalledWith(err)
expect(errorMock).toHaveBeenCalledWith(cause)
})

it('opens release url (repository name)', async () => {
Expand Down