@@ -2,7 +2,7 @@ import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/server-r
2
2
import { json } from "@remix-run/server-runtime" ;
3
3
import { ScheduleObject , UpdateScheduleOptions } from "@trigger.dev/core/v3" ;
4
4
import { z } from "zod" ;
5
- import { prisma } from "~/db.server" ;
5
+ import { Prisma , prisma } from "~/db.server" ;
6
6
import { ViewSchedulePresenter } from "~/presenters/v3/ViewSchedulePresenter.server" ;
7
7
import { authenticateApiRequest } from "~/services/apiAuth.server" ;
8
8
import { UpsertSchedule } from "~/v3/schedules" ;
@@ -34,19 +34,34 @@ export async function action({ request, params }: ActionFunctionArgs) {
34
34
35
35
switch ( method ) {
36
36
case "DELETE" : {
37
- const deletedSchedule = await prisma . taskSchedule . delete ( {
38
- where : {
39
- friendlyId : parsedParams . data . scheduleId ,
40
- projectId : authenticationResult . environment . projectId ,
41
- } ,
42
- } ) ;
43
-
44
- return json (
45
- {
46
- id : deletedSchedule . friendlyId ,
47
- } ,
48
- { status : 200 }
49
- ) ;
37
+ try {
38
+ const deletedSchedule = await prisma . taskSchedule . delete ( {
39
+ where : {
40
+ friendlyId : parsedParams . data . scheduleId ,
41
+ projectId : authenticationResult . environment . projectId ,
42
+ } ,
43
+ } ) ;
44
+
45
+ return json (
46
+ {
47
+ id : deletedSchedule . friendlyId ,
48
+ } ,
49
+ { status : 200 }
50
+ ) ;
51
+ } catch ( error ) {
52
+ // Check if it's a Prisma error
53
+ if ( error instanceof Prisma . PrismaClientKnownRequestError ) {
54
+ return json (
55
+ { error : error . code === "P2025" ? "Schedule not found" : error . message } ,
56
+ { status : error . code === "P2025" ? 404 : 422 }
57
+ ) ;
58
+ } else {
59
+ return json (
60
+ { error : error instanceof Error ? error . message : "Internal Server Error" } ,
61
+ { status : 500 }
62
+ ) ;
63
+ }
64
+ }
50
65
}
51
66
case "PUT" : {
52
67
const rawBody = await request . json ( ) ;
0 commit comments