Skip to content

Commit

Permalink
fix(secrets): skip already existing secrets while creating (#6099)
Browse files Browse the repository at this point in the history
* fix(secrets): skip already existing secrets while creating

* improvement: more informative error message on failure

Show user-friendly error message
instead of printing plain HTTP error code and original low-level error message.

* fix: spacing in error renderer
  • Loading branch information
vvagaytsev committed May 29, 2024
1 parent 0cc7924 commit 65ceb7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions core/src/cloud/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { LogLevel } from "../logger/logger.js"
import { makeAuthHeader } from "./auth.js"
import type { StringMap } from "../config/common.js"
import { styles } from "../logger/styles.js"
import { RequestError } from "got"
import { HTTPError, RequestError } from "got"
import type { Garden } from "../garden.js"
import type { ApiCommandError } from "../commands/cloud/helpers.js"
import { enumerate } from "../util/enumerate.js"
Expand Down Expand Up @@ -939,13 +939,19 @@ export class CloudApi {
const res = await this.createSecret(body)
results.push(res.data)
} catch (err) {
if (!(err instanceof GardenError)) {
if (!(err instanceof HTTPError)) {
throw err
}

// skip already existing secret and continue the loop
if (err.response.statusCode === 409) {
errors.push({
identifier: name,
message: "Secret already exists",
})
} else {
throw err
}
errors.push({
identifier: name,
message: err.message,
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/commands/cloud/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function handleBulkOperationResult<T>({
? `with ID ${e.identifier} `
: e.identifier === ""
? ""
: `"${e.identifier} "`
: `"${e.identifier}" `
return `→ ${capitalize(actionVerb)} ${resource} ${identifier}failed with error: ${e.message}`
})
.join("\n")
Expand Down

0 comments on commit 65ceb7c

Please sign in to comment.