Skip to content

Commit

Permalink
Universally handle generic 403 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianruesch committed Nov 12, 2023
1 parent cf84f14 commit 053ef38
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions electron/providers/jira-cloud-provider/JiraCloudProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class JiraCloudProvider implements IProvider {
return Promise.reject(recreateAxiosError(error, `Invalid request: ${JSON.stringify(error.response.data)}`))
} else if (statusCode === 401) {
return Promise.reject(recreateAxiosError(error, `User not authenticated: ${JSON.stringify(error.response.data)}`))
} else if (error.response.status === 403) {
return Promise.reject(recreateAxiosError(error, `User does not have a valid licence: ${JSON.stringify(error.response.data)}`))
} else if (error.response.status === 429) {
return Promise.reject(recreateAxiosError(error, `Rate limit exceeded: ${JSON.stringify(error.response.data)}`))
}
Expand Down Expand Up @@ -342,14 +344,7 @@ export class JiraCloudProvider implements IProvider {
resolve(boardIds)
})
.catch((error) => {
let specificError = error
if (error.response) {
if (error.response.status === 403) {
specificError = new Error(`User does not have a valid licence: ${error.response.data}`)
}
}

reject(new Error(`Error getting projects: ${specificError}`))
reject(new Error(`Error getting projects: ${error}`))
})
})
}
Expand Down Expand Up @@ -385,9 +380,7 @@ export class JiraCloudProvider implements IProvider {
.catch((error) => {
let specificError = error
if (error.response) {
if (error.response.status === 403) {
specificError = new Error(`User does not have a valid licence: ${error.response.data}`)
} else if (error.response.status === 404) {
if (error.response.status === 404) {
specificError = new Error(
`The board does not exist or the user does not have permission to view it: ${error.response.data}`
)
Expand Down Expand Up @@ -478,9 +471,7 @@ export class JiraCloudProvider implements IProvider {
return error;
}

if (error.response.status === 403) {
return new Error(`User does not have a valid licence: ${error.response.data}`)
} else if (error.response.status === 404) {
if (error.response.status === 404) {
return new Error(
`The board does not exist or the user does not have permission to view it: ${error.response.data}`
)
Expand Down Expand Up @@ -808,11 +799,7 @@ export class JiraCloudProvider implements IProvider {
.catch((error) => {
let specificError = error
if (error.response) {
if (error.response.status === 403) {
specificError = new Error(
"The user does not have the necessary permissions"
)
} else if (error.response.status === 404) {
if (error.response.status === 404) {
specificError = new Error(
"The issue was not found or the user does not have the necessary permissions"
)
Expand Down Expand Up @@ -864,9 +851,7 @@ export class JiraCloudProvider implements IProvider {
.catch((error) => {
let specificError = error
if (error.response) {
if (error.response.status === 403) {
specificError = new Error(`User does not have a valid licence: ${error.response.data}`)
} else if (error.response.status === 404) {
if (error.response.status === 404) {
specificError = new Error(
`The board does not exist or the user does not have permission to view it: ${error.response.data}`
)
Expand Down Expand Up @@ -1066,14 +1051,7 @@ export class JiraCloudProvider implements IProvider {
resolve(createdSubtask)
})
.catch((error) => {
let specificError = error
if (error.response) {
if (error.response.status === 403) {
specificError = new Error(`User does not have a valid licence: ${error.response.data}`)
}
}

reject(new Error(`Error creating subtask: ${specificError}`))
reject(new Error(`Error creating subtask: ${error}`))
})
})
}
Expand Down

0 comments on commit 053ef38

Please sign in to comment.