Skip to content
Draft
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
12 changes: 12 additions & 0 deletions packages/cli-v3/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,18 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
"",
$spinner
);
} else if ("error" in uploadResult.data) {
// Server returned 200 but with error in body
await failDeploy(
projectClient.client,
deployment,
{
name: "SyncEnvVarsError",
message: `Failed to sync ${numberOfEnvVars} env ${vars} with the server: ${uploadResult.data.error}`,
},
"",
$spinner
);
} else {
$spinner.stop(`Successfully synced ${numberOfEnvVars} env ${vars} with the server`);
}
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/v3/schemas/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,15 @@ export type ImportEnvironmentVariablesRequestBody = z.infer<
typeof ImportEnvironmentVariablesRequestBody
>;

export const EnvironmentVariableResponseBody = z.object({
success: z.boolean(),
});
export const EnvironmentVariableResponseBody = z.union([
z.object({
success: z.literal(true),
}),
z.object({
error: z.string(),
variableErrors: z.array(z.any()).optional(),
}),
]);

export type EnvironmentVariableResponseBody = z.infer<typeof EnvironmentVariableResponseBody>;

Expand Down
53 changes: 53 additions & 0 deletions packages/core/test/environmentVariableResponse.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { EnvironmentVariableResponseBody } from "../src/v3/schemas/api.js";

describe("EnvironmentVariableResponseBody schema", () => {
it("should accept success response", () => {
const successResponse = { success: true };
const result = EnvironmentVariableResponseBody.safeParse(successResponse);

expect(result.success).toBe(true);
if (result.success) {
expect(result.data).toEqual({ success: true });
}
});

it("should accept error response with error field", () => {
const errorResponse = { error: "Something went wrong" };
const result = EnvironmentVariableResponseBody.safeParse(errorResponse);

expect(result.success).toBe(true);
if (result.success) {
expect(result.data).toEqual({ error: "Something went wrong" });
}
});

it("should accept error response with error and variableErrors fields", () => {
const errorResponse = {
error: "Variable validation failed",
variableErrors: ["Invalid variable name", "Value too long"]
};
const result = EnvironmentVariableResponseBody.safeParse(errorResponse);

expect(result.success).toBe(true);
if (result.success) {
expect(result.data).toEqual({
error: "Variable validation failed",
variableErrors: ["Invalid variable name", "Value too long"]
});
}
});

it("should reject response without success or error field", () => {
const invalidResponse = { something: "else" };
const result = EnvironmentVariableResponseBody.safeParse(invalidResponse);

expect(result.success).toBe(false);
});

it("should reject response with success: false", () => {
const invalidResponse = { success: false };
const result = EnvironmentVariableResponseBody.safeParse(invalidResponse);

expect(result.success).toBe(false);
});
});