@@ -34,6 +34,7 @@ import {
34
34
v3BillingAlertsPath ,
35
35
} from "~/utils/pathBuilder" ;
36
36
import { useCurrentPlan } from "../_app.orgs.$organizationSlug/route" ;
37
+ import { tryCatch } from "@trigger.dev/core" ;
37
38
38
39
export const meta : MetaFunction = ( ) => {
39
40
return [
@@ -60,7 +61,11 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
60
61
throw new Response ( null , { status : 404 , statusText : "Organization not found" } ) ;
61
62
}
62
63
63
- const alerts = await getBillingAlerts ( organization . id ) ;
64
+ const [ error , alerts ] = await tryCatch ( getBillingAlerts ( organization . id ) ) ;
65
+ if ( error ) {
66
+ throw new Response ( null , { status : 404 , statusText : `Billing alerts error: ${ error } ` } ) ;
67
+ }
68
+
64
69
if ( ! alerts ) {
65
70
throw new Response ( null , { status : 404 , statusText : "Billing alerts not found" } ) ;
66
71
}
@@ -120,10 +125,20 @@ export const action: ActionFunction = async ({ request, params }) => {
120
125
) ;
121
126
}
122
127
123
- const updatedAlert = await setBillingAlert ( organization . id , {
124
- ...submission . value ,
125
- amount : submission . value . amount * 100 ,
126
- } ) ;
128
+ const [ error , updatedAlert ] = await tryCatch (
129
+ setBillingAlert ( organization . id , {
130
+ ...submission . value ,
131
+ amount : submission . value . amount * 100 ,
132
+ } )
133
+ ) ;
134
+ if ( error ) {
135
+ return redirectWithErrorMessage (
136
+ v3BillingAlertsPath ( { slug : organizationSlug } ) ,
137
+ request ,
138
+ "Failed to update billing alert"
139
+ ) ;
140
+ }
141
+
127
142
if ( ! updatedAlert ) {
128
143
return redirectWithErrorMessage (
129
144
v3BillingAlertsPath ( { slug : organizationSlug } ) ,
@@ -170,7 +185,7 @@ export default function Page() {
170
185
if ( alerts . emails . length > 0 ) {
171
186
requestIntent ( form . ref . current ?? undefined , list . append ( emails . name ) ) ;
172
187
}
173
- } , [ alerts . emails , emails . name , form . ref ] ) ;
188
+ } , [ emails . name , form . ref ] ) ;
174
189
const isFree = ! plan ?. v3Subscription ?. isPaying ;
175
190
176
191
return (
0 commit comments