@@ -34,6 +34,7 @@ import {
3434 v3BillingAlertsPath ,
3535} from "~/utils/pathBuilder" ;
3636import { useCurrentPlan } from "../_app.orgs.$organizationSlug/route" ;
37+ import { tryCatch } from "@trigger.dev/core" ;
3738
3839export const meta : MetaFunction = ( ) => {
3940 return [
@@ -60,7 +61,11 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
6061 throw new Response ( null , { status : 404 , statusText : "Organization not found" } ) ;
6162 }
6263
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+
6469 if ( ! alerts ) {
6570 throw new Response ( null , { status : 404 , statusText : "Billing alerts not found" } ) ;
6671 }
@@ -120,10 +125,20 @@ export const action: ActionFunction = async ({ request, params }) => {
120125 ) ;
121126 }
122127
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+
127142 if ( ! updatedAlert ) {
128143 return redirectWithErrorMessage (
129144 v3BillingAlertsPath ( { slug : organizationSlug } ) ,
@@ -170,7 +185,7 @@ export default function Page() {
170185 if ( alerts . emails . length > 0 ) {
171186 requestIntent ( form . ref . current ?? undefined , list . append ( emails . name ) ) ;
172187 }
173- } , [ alerts . emails , emails . name , form . ref ] ) ;
188+ } , [ emails . name , form . ref ] ) ;
174189 const isFree = ! plan ?. v3Subscription ?. isPaying ;
175190
176191 return (
0 commit comments