Skip to content

Commit

Permalink
Added method for error handling which could be reused in other applic…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
MarcelGeo committed Dec 18, 2024
1 parent df13893 commit 7d6b336
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 4 additions & 2 deletions web-app/packages/lib/src/modules/project/projectApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ export const ProjectApi = {
`/v2/projects/${id}/collaborators/${userId}`,
data,
{
...(withRetry ? getDefaultRetryOptions() : {})
...(withRetry ? getDefaultRetryOptions() : {}),
validateStatus
}
)
},
Expand All @@ -207,7 +208,8 @@ export const ProjectApi = {
return ProjectModule.httpService.delete(
`/v2/projects/${id}/collaborators/${userId}`,
{
...(withRetry ? getDefaultRetryOptions() : {})
...(withRetry ? getDefaultRetryOptions() : {}),
validateStatus
}
)
},
Expand Down
17 changes: 10 additions & 7 deletions web-app/packages/lib/src/modules/project/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
SaveProjectSettings,
ErrorCodes,
ProjectAccessDetail,
UpdateProjectAccessParams,
ProjectVersionFileChange,
ProjectVersionListItem,
UpdateProjectPayload,
Expand Down Expand Up @@ -757,8 +756,8 @@ export const useProjectStore = defineStore('projectModule', {
async removeProjectAccess(
item: Pick<ProjectAccessDetail, 'id' | 'username'>
) {
const notificationStore = useNotificationStore()
this.accessLoading = true
const notificationStore = useNotificationStore()
try {
const response = await ProjectApi.removeProjectAccess(
this.project.id,
Expand Down Expand Up @@ -786,7 +785,6 @@ export const useProjectStore = defineStore('projectModule', {
userId: number
data: UpdateProjectPayload
}) {
const notificationStore = useNotificationStore()
this.accessLoading = true
try {
const response = await ProjectApi.updateProjectAccess(
Expand All @@ -801,15 +799,20 @@ export const useProjectStore = defineStore('projectModule', {
return access
})
this.project.access = response.data
} catch {
notificationStore.error({
text: `Failed to update project access`
})
} catch (err) {
this.handleProjectAccessError(err, 'Failed to update project access')
} finally {
this.accessLoading = false
}
},

handleProjectAccessError(err: unknown, defaultMessage: string) {
const notificationStore = useNotificationStore()
notificationStore.error({
text: getErrorMessage(err, defaultMessage)
})
},

async updatePublicFlag(payload: {
projectId: string
data: UpdatePublicFlagParams
Expand Down

0 comments on commit 7d6b336

Please sign in to comment.