File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -135,13 +135,25 @@ export async function createOrganization(
135135 return { ...organization } ;
136136}
137137
138+ // The platform client has no request timeout; don't let a slow billing backend stall org creation.
139+ const SEED_ALERTS_TIMEOUT_MS = 5_000 ;
140+
138141/** Seed default billing alerts for a new org. Never fails org creation. */
139142async function seedDefaultBillingAlerts ( organizationId : string ) : Promise < void > {
140143 if ( ! isBillingConfigured ( ) ) {
141144 return ;
142145 }
143146
144- const [ error ] = await tryCatch ( setBillingAlert ( organizationId , buildDefaultBillingAlerts ( ) ) ) ;
147+ let timer : NodeJS . Timeout | undefined ;
148+ const timeout = new Promise < never > ( ( _ , reject ) => {
149+ timer = setTimeout ( ( ) => reject ( new Error ( "Timed out" ) ) , SEED_ALERTS_TIMEOUT_MS ) ;
150+ } ) ;
151+
152+ const [ error ] = await tryCatch (
153+ Promise . race ( [ setBillingAlert ( organizationId , buildDefaultBillingAlerts ( ) ) , timeout ] ) . finally (
154+ ( ) => clearTimeout ( timer )
155+ )
156+ ) ;
145157 if ( error ) {
146158 logger . warn ( "Failed to seed default billing alerts for new org" , {
147159 organizationId,
You can’t perform that action at this time.
0 commit comments