@@ -21,6 +21,7 @@ import { inject, injectable } from "inversify";
2121import { EntitlementService , HitParallelWorkspaceLimit , MayStartWorkspaceResult } from "./entitlement-service" ;
2222import { CostCenter_BillingStrategy } from "@gitpod/usage-api/lib/usage/v1/usage.pb" ;
2323import { UsageService } from "../orgs/usage-service" ;
24+ import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
2425
2526const MAX_PARALLEL_WORKSPACES_FREE = 4 ;
2627const MAX_PARALLEL_WORKSPACES_PAID = 16 ;
@@ -110,10 +111,17 @@ export class EntitlementServiceUBP implements EntitlementService {
110111
111112 private async hasPaidSubscription ( userId : string , organizationId ?: string ) : Promise < boolean > {
112113 if ( organizationId ) {
113- // This is the "stricter", more correct version: We only allow privileges on the Organization that is paying for it
114- const { billingStrategy } = await this . usageService . getCostCenter ( userId , organizationId ) ;
115- return billingStrategy === CostCenter_BillingStrategy . BILLING_STRATEGY_STRIPE ;
114+ try {
115+ // This is the "stricter", more correct version: We only allow privileges on the Organization that is paying for it
116+ const { billingStrategy } = await this . usageService . getCostCenter ( userId , organizationId ) ;
117+ return billingStrategy === CostCenter_BillingStrategy . BILLING_STRATEGY_STRIPE ;
118+ } catch ( err ) {
119+ log . warn ( { userId, organizationId } , "Error checking if user is subscribed to organization" , err ) ;
120+ return false ;
121+ }
116122 }
123+
124+ // TODO(gpl) Remove everything below once organizations are fully rolled out
117125 // This is the old behavior, stemming from our transition to PAYF, where our API did-/doesn't pass organizationId, yet
118126 // Member of paid team?
119127 const teams = await this . teamDB . findTeamsByUser ( userId ) ;
@@ -126,8 +134,13 @@ export class EntitlementServiceUBP implements EntitlementService {
126134 return new Promise ( ( resolve , reject ) => {
127135 // If any promise returns true, immediately resolve with true
128136 isTeamSubscribedPromises . forEach ( async ( isTeamSubscribedPromise : Promise < boolean > ) => {
129- const isTeamSubscribed = await isTeamSubscribedPromise ;
130- if ( isTeamSubscribed ) resolve ( true ) ;
137+ try {
138+ const isTeamSubscribed = await isTeamSubscribedPromise ;
139+ if ( isTeamSubscribed ) resolve ( true ) ;
140+ } catch ( err ) {
141+ log . warn ( { userId, organizationId } , "Error checking if user is subscribed to organization" , err ) ;
142+ resolve ( false ) ;
143+ }
131144 } ) ;
132145
133146 // If neither of the above fires, resolve with false
0 commit comments