@@ -18,6 +18,7 @@ import {
1818 formatDurationMilliseconds ,
1919 millisecondsToNanoseconds ,
2020 nanosecondsToMilliseconds ,
21+ tryCatch ,
2122} from "@trigger.dev/core/v3" ;
2223import { type RuntimeEnvironmentType } from "@trigger.dev/database" ;
2324import { motion } from "framer-motion" ;
@@ -77,7 +78,7 @@ import { useProject } from "~/hooks/useProject";
7778import { useReplaceSearchParams } from "~/hooks/useReplaceSearchParams" ;
7879import { type Shortcut , useShortcutKeys } from "~/hooks/useShortcutKeys" ;
7980import { useHasAdminAccess } from "~/hooks/useUser" ;
80- import { RunPresenter } from "~/presenters/v3/RunPresenter.server" ;
81+ import { RunEnvironmentMismatchError , RunPresenter } from "~/presenters/v3/RunPresenter.server" ;
8182import { getImpersonationId } from "~/services/impersonation.server" ;
8283import { getResizableSnapshot } from "~/services/resizablePanel.server" ;
8384import { requireUserId } from "~/services/session.server" ;
@@ -88,12 +89,15 @@ import {
8889 v3BillingPath ,
8990 v3RunParamsSchema ,
9091 v3RunPath ,
92+ v3RunRedirectPath ,
9193 v3RunSpanPath ,
9294 v3RunStreamingPath ,
9395 v3RunsPath ,
9496} from "~/utils/pathBuilder" ;
9597import { useCurrentPlan } from "../_app.orgs.$organizationSlug/route" ;
9698import { SpanView } from "../resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.spans.$spanParam/route" ;
99+ import { redirectWithErrorMessage } from "~/models/message.server" ;
100+ import { redirect } from "remix-typedjson" ;
97101
98102const resizableSettings = {
99103 parent : {
@@ -133,13 +137,30 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
133137 const { projectParam, organizationSlug, envParam, runParam } = v3RunParamsSchema . parse ( params ) ;
134138
135139 const presenter = new RunPresenter ( ) ;
136- const result = await presenter . call ( {
137- userId,
138- organizationSlug,
139- showDeletedLogs : ! ! impersonationId ,
140- projectSlug : projectParam ,
141- runFriendlyId : runParam ,
142- } ) ;
140+ const [ error , result ] = await tryCatch (
141+ presenter . call ( {
142+ userId,
143+ organizationSlug,
144+ showDeletedLogs : ! ! impersonationId ,
145+ projectSlug : projectParam ,
146+ runFriendlyId : runParam ,
147+ environmentSlug : envParam ,
148+ } )
149+ ) ;
150+
151+ if ( error ) {
152+ if ( error instanceof RunEnvironmentMismatchError ) {
153+ throw redirect (
154+ v3RunRedirectPath (
155+ { slug : organizationSlug } ,
156+ { slug : projectParam } ,
157+ { friendlyId : runParam }
158+ )
159+ ) ;
160+ }
161+
162+ throw error ;
163+ }
143164
144165 //resizable settings
145166 const parent = await getResizableSnapshot ( request , resizableSettings . parent . autosaveId ) ;
0 commit comments