Skip to content

Commit 1e2869d

Browse files
committed
Re-running and retrying behaves properly when there’s no endpoint URL
1 parent 9ee395e commit 1e2869d

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

apps/webapp/app/components/run/RunOverview.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export function RunOverview({ run, trigger, showRerun, paths, currentUser }: Run
117117
{showRerun && run.isFinished && (
118118
<RerunPopover
119119
runId={run.id}
120+
runPath={paths.run}
120121
runsPath={paths.runsPath}
121122
environmentType={run.environment.type}
122123
status={run.basicStatus}
@@ -317,18 +318,20 @@ function BlankTasks({ status }: { status: RunBasicStatus }) {
317318

318319
function RerunPopover({
319320
runId,
321+
runPath,
320322
runsPath,
321323
environmentType,
322324
status,
323325
}: {
324326
runId: string;
327+
runPath: string;
325328
runsPath: string;
326329
environmentType: RuntimeEnvironmentType;
327330
status: RunBasicStatus;
328331
}) {
329332
const lastSubmission = useActionData();
330333

331-
const [form, { successRedirect }] = useForm({
334+
const [form, { successRedirect, failureRedirect }] = useForm({
332335
id: "rerun",
333336
// TODO: type this
334337
lastSubmission: lastSubmission as any,
@@ -347,6 +350,7 @@ function RerunPopover({
347350
<PopoverContent className="flex min-w-[20rem] max-w-[20rem] flex-col gap-2 p-0" align="end">
348351
<Form method="post" action={`/resources/runs/${runId}/rerun`} {...form.props}>
349352
<input {...conform.input(successRedirect, { type: "hidden" })} defaultValue={runsPath} />
353+
<input {...conform.input(failureRedirect, { type: "hidden" })} defaultValue={runPath} />
350354
{environmentType === "PRODUCTION" && (
351355
<div className="px-4 pt-4">
352356
<Callout variant="warning">

apps/webapp/app/routes/resources.runs.$runId.rerun.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { parse } from "@conform-to/zod";
22
import { ActionFunction, json } from "@remix-run/node";
33
import { z } from "zod";
4-
import { redirectBackWithErrorMessage, redirectWithSuccessMessage } from "~/models/message.server";
4+
import {
5+
redirectBackWithErrorMessage,
6+
redirectWithErrorMessage,
7+
redirectWithSuccessMessage,
8+
} from "~/models/message.server";
59
import { ContinueRunService } from "~/services/runs/continueRun.server";
610
import { ReRunService } from "~/services/runs/reRun.server";
11+
import { rootPath, runPath } from "~/utils/pathBuilder";
712

813
export const schema = z.object({
914
successRedirect: z.string(),
15+
failureRedirect: z.string(),
1016
});
1117

1218
const ParamSchema = z.object({
@@ -19,8 +25,14 @@ export const action: ActionFunction = async ({ request, params }) => {
1925
const formData = await request.formData();
2026
const submission = parse(formData, { schema });
2127

28+
console.log(submission);
29+
2230
if (!submission.value) {
23-
return json(submission);
31+
return redirectWithErrorMessage(
32+
rootPath(),
33+
request,
34+
submission.error ? JSON.stringify(submission.error) : "Invalid form"
35+
);
2436
}
2537

2638
try {
@@ -29,7 +41,11 @@ export const action: ActionFunction = async ({ request, params }) => {
2941
const run = await rerunService.call({ runId });
3042

3143
if (!run) {
32-
return redirectBackWithErrorMessage(request, "Unable to retry run");
44+
return redirectWithErrorMessage(
45+
submission.value.failureRedirect,
46+
request,
47+
"Unable to retry run"
48+
);
3349
}
3450

3551
return redirectWithSuccessMessage(
@@ -48,6 +64,10 @@ export const action: ActionFunction = async ({ request, params }) => {
4864
);
4965
}
5066
} catch (error: any) {
51-
return json({ errors: { body: error.message } }, { status: 400 });
67+
return redirectWithErrorMessage(
68+
submission.value.failureRedirect,
69+
request,
70+
error instanceof Error ? error.message : JSON.stringify(error)
71+
);
5272
}
5373
};

0 commit comments

Comments
 (0)