Skip to content

Commit

Permalink
Print meaningful error message when user tries to delete a running wo…
Browse files Browse the repository at this point in the history
…rkspace (#806)

Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha authored Jul 31, 2020
1 parent cf7baad commit a889d06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/api/che.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,17 @@ export class CheHelper {
async getWorkspace(cheUrl: string, workspaceId: string, accessToken = ''): Promise<any> {
const endpoint = `${cheUrl}/api/workspace/${workspaceId}`
const headers: any = { 'Content-Type': 'text/yaml' }
if (accessToken && accessToken.length > 0) {
if (accessToken) {
headers.Authorization = `${accessToken}`
}

try {
const response = await this.axios.get(endpoint, { headers })
return response.data
} catch (error) {
if (error.response.status === 404) {
throw new Error(`Workspace ${workspaceId} not found. Please use the command workspace:list to get list of the existed workspaces.`)
}
throw this.getCheApiError(error, endpoint)
}
}
Expand All @@ -572,8 +575,10 @@ export class CheHelper {
try {
await this.axios.delete(endpoint, { headers })
} catch (error) {
if (error.response.status === 409) {
throw new Error(`Workspace '${workspaceId}' not found`)
if (error.response.status === 404) {
throw new Error(`Workspace ${workspaceId} not found. Please use the command workspace:list to get list of the existed workspaces.`)
} else if (error.response.status === 409) {
throw new Error('Cannot delete a running workspace. Please stop it using the command workspace:stop and try again')
}
throw this.getCheApiError(error, endpoint)
}
Expand Down Expand Up @@ -629,7 +634,7 @@ export class CheHelper {
return fileName
}

private getCheApiError(error: any, endpoint: string): Error {
getCheApiError(error: any, endpoint: string): Error {
if (error.response) {
const status = error.response.status
if (status === 403) {
Expand Down
1 change: 1 addition & 0 deletions src/commands/workspace/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class Delete extends Command {
tasks.add(cheTasks.verifyCheNamespaceExistsTask(flags, this))
tasks.add(cheTasks.retrieveEclipseCheUrl(flags))
tasks.add(cheTasks.checkEclipseCheStatus())

tasks.add({
title: `Get workspace by id '${args.workspace}'`,
task: async (ctx, task) => {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1544,11 +1544,11 @@ ecc-jsbn@~0.1.1:

"eclipse-che-operator@git://github.com/eclipse/che-operator#master":
version "0.0.0"
resolved "git://github.com/eclipse/che-operator#c4a3ff2480740190f97feb3e6c85029506561e8c"
resolved "git://github.com/eclipse/che-operator#c64d61faf4f7b5eb13ee1d91e0ee90c8a84b3b8c"

"eclipse-che@git://github.com/eclipse/che#master":
version "0.0.0"
resolved "git://github.com/eclipse/che#593f91515f368dc6d76e1f09113e4d61c562aa46"
resolved "git://github.com/eclipse/che#cc7fd4e75e45e632e3d8f704ac2d0ce8365e55ce"

editorconfig@^0.15.0:
version "0.15.3"
Expand Down

0 comments on commit a889d06

Please sign in to comment.