@@ -118,19 +118,20 @@ export class Polar<
118118 userId,
119119 }
120120 ) ;
121- const customerId =
122- dbCustomer ?. id ||
123- (
124- await customersCreate ( this . polar , {
125- email,
126- metadata : {
127- userId,
128- } ,
129- } )
130- ) . value ?. id ;
131- if ( ! customerId ) {
132- throw new Error ( "Customer not created" ) ;
133- }
121+ const createCustomer = async ( ) => {
122+ const customer = await customersCreate ( this . polar , {
123+ email,
124+ metadata : {
125+ userId,
126+ } ,
127+ } ) ;
128+ if ( ! customer . value ) {
129+ console . error ( customer ) ;
130+ throw new Error ( "Customer not created" ) ;
131+ }
132+ return customer . value ;
133+ } ;
134+ const customerId = dbCustomer ?. id || ( await createCustomer ( ) ) . id ;
134135 if ( ! dbCustomer ) {
135136 await ctx . runMutation ( this . component . lib . insertCustomer , {
136137 id : customerId ,
@@ -169,6 +170,7 @@ export class Polar<
169170 customerId : customer . id ,
170171 } ) ;
171172 if ( ! session . value ) {
173+ console . error ( session ) ;
172174 throw new Error ( "Customer session not created" ) ;
173175 }
174176
@@ -232,6 +234,7 @@ export class Polar<
232234 } ,
233235 } ) ;
234236 if ( ! updatedSubscription . value ) {
237+ console . error ( updatedSubscription ) ;
235238 throw new Error ( "Subscription not updated" ) ;
236239 }
237240 return updatedSubscription . value ;
@@ -256,6 +259,7 @@ export class Polar<
256259 } ,
257260 } ) ;
258261 if ( ! updatedSubscription . value ) {
262+ console . error ( updatedSubscription ) ;
259263 throw new Error ( "Subscription not updated" ) ;
260264 }
261265 return updatedSubscription . value ;
0 commit comments