@@ -203,9 +203,12 @@ export class UserService {
203
203
return subscription ?. id ;
204
204
}
205
205
206
- protected async validateUsageAttributionId ( user : User , usageAttributionId : string ) : Promise < void > {
206
+ protected async validateUsageAttributionId ( user : User , usageAttributionId : string ) : Promise < AttributionId > {
207
207
const attribution = AttributionId . parse ( usageAttributionId ) ;
208
- if ( attribution ?. kind === "team" ) {
208
+ if ( ! attribution ) {
209
+ throw new ResponseError ( ErrorCodes . INVALID_COST_CENTER , "The billing team id configured is invalid." ) ;
210
+ }
211
+ if ( attribution . kind === "team" ) {
209
212
const team = await this . teamDB . findTeamById ( attribution . teamId ) ;
210
213
if ( ! team ) {
211
214
throw new ResponseError (
@@ -228,6 +231,7 @@ export class UserService {
228
231
) ;
229
232
}
230
233
}
234
+ return attribution ;
231
235
}
232
236
233
237
protected async findSingleTeamWithUsageBasedBilling ( user : User ) : Promise < Team | undefined > {
@@ -268,14 +272,14 @@ export class UserService {
268
272
*
269
273
* @param user
270
274
* @param projectId
275
+ * @returns The validated AttributionId
271
276
*/
272
- async getWorkspaceUsageAttributionId ( user : User , projectId ?: string ) : Promise < AttributionId | undefined > {
277
+ async getWorkspaceUsageAttributionId ( user : User , projectId ?: string ) : Promise < AttributionId > {
273
278
// A. Billing-based attribution
274
279
if ( this . config . enablePayment ) {
275
280
if ( user . usageAttributionId ) {
276
- await this . validateUsageAttributionId ( user , user . usageAttributionId ) ;
277
281
// Return the user's explicit attribution ID.
278
- return AttributionId . parse ( user . usageAttributionId ) ;
282
+ return await this . validateUsageAttributionId ( user , user . usageAttributionId ) ;
279
283
}
280
284
const billingTeam = await this . findSingleTeamWithUsageBasedBilling ( user ) ;
281
285
if ( billingTeam ) {
0 commit comments