@@ -15,7 +15,9 @@ import { PreValidateSponsorshipResponse } from "@bitwarden/common/admin-console/
1515import { AccountService } from "@bitwarden/common/auth/abstractions/account.service" ;
1616import { getUserId } from "@bitwarden/common/auth/services/account.service" ;
1717import { PlanSponsorshipType , PlanType , ProductTierType } from "@bitwarden/common/billing/enums" ;
18+ import { ErrorResponse } from "@bitwarden/common/models/response/error.response" ;
1819import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service" ;
20+ import { LogService } from "@bitwarden/common/platform/abstractions/log.service" ;
1921import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service" ;
2022import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction" ;
2123import { DialogService , ToastService } from "@bitwarden/components" ;
@@ -65,6 +67,7 @@ export class FamiliesForEnterpriseSetupComponent implements OnInit, OnDestroy {
6567 private dialogService : DialogService ,
6668 private formBuilder : FormBuilder ,
6769 private toastService : ToastService ,
70+ private logService : LogService ,
6871 ) { }
6972
7073 async ngOnInit ( ) {
@@ -73,6 +76,7 @@ export class FamiliesForEnterpriseSetupComponent implements OnInit, OnDestroy {
7376 this . route . queryParams . pipe ( first ( ) ) . subscribe ( async ( qParams ) => {
7477 const error = qParams . token == null ;
7578 if ( error ) {
79+ this . logService . warning ( "[Sponsorship] No token found in query params" ) ;
7680 this . toastService . showToast ( {
7781 variant : "error" ,
7882 title : null ,
@@ -86,12 +90,20 @@ export class FamiliesForEnterpriseSetupComponent implements OnInit, OnDestroy {
8690 }
8791
8892 this . token = qParams . token ;
93+ this . logService . info (
94+ `[Sponsorship] Token present (length=${ this . token . length } ), starting validation` ,
95+ ) ;
8996
9097 await this . syncService . fullSync ( true ) ;
9198
9299 this . preValidateSponsorshipResponse = await this . apiService . postPreValidateSponsorshipToken (
93100 this . token ,
94101 ) ;
102+
103+ this . logService . info (
104+ `[Sponsorship] Pre-validation result: isTokenValid=${ this . preValidateSponsorshipResponse . isTokenValid } , isFreeFamilyPolicyEnabled=${ this . preValidateSponsorshipResponse . isFreeFamilyPolicyEnabled } ` ,
105+ ) ;
106+
95107 if ( this . preValidateSponsorshipResponse . isFreeFamilyPolicyEnabled ) {
96108 this . toastService . showToast ( {
97109 variant : "error" ,
@@ -152,12 +164,18 @@ export class FamiliesForEnterpriseSetupComponent implements OnInit, OnDestroy {
152164 }
153165
154166 private async doSubmit ( organizationId : string ) {
167+ this . logService . info (
168+ `[Sponsorship] Redeem started: organizationId=${ organizationId } , showNewOrganization=${ this . showNewOrganization } , tokenLength=${ this . token ?. length } ` ,
169+ ) ;
170+
155171 try {
156172 const request = new OrganizationSponsorshipRedeemRequest ( ) ;
157173 request . planSponsorshipType = PlanSponsorshipType . FamiliesForEnterprise ;
158174 request . sponsoredOrganizationId = organizationId ;
159175
160176 await this . apiService . postRedeemSponsorship ( this . token , request ) ;
177+
178+ this . logService . info ( "[Sponsorship] Redeem succeeded" ) ;
161179 this . toastService . showToast ( {
162180 variant : "success" ,
163181 title : null ,
@@ -169,9 +187,19 @@ export class FamiliesForEnterpriseSetupComponent implements OnInit, OnDestroy {
169187 // eslint-disable-next-line @typescript-eslint/no-floating-promises
170188 this . router . navigate ( [ "/" ] ) ;
171189 // FIXME: Remove when updating file. Eslint update
172- // eslint-disable-next-line @typescript-eslint/no-unused-vars
173190 } catch ( e ) {
191+ if ( e instanceof ErrorResponse ) {
192+ this . logService . error (
193+ `[Sponsorship] Redeem failed: statusCode=${ e . statusCode } , message="${ e . message } ", validationErrors=${ JSON . stringify ( e . validationErrors ) } ` ,
194+ ) ;
195+ } else {
196+ this . logService . error ( `[Sponsorship] Redeem failed with unexpected error: ${ e } ` ) ;
197+ }
198+
174199 if ( this . showNewOrganization ) {
200+ this . logService . warning (
201+ `[Sponsorship] Opening delete dialog for newly created org: organizationId=${ organizationId } ` ,
202+ ) ;
175203 const dialog = openDeleteOrganizationDialog ( this . dialogService , {
176204 data : {
177205 organizationId : organizationId ,
@@ -192,6 +220,9 @@ export class FamiliesForEnterpriseSetupComponent implements OnInit, OnDestroy {
192220 }
193221
194222 protected async onOrganizationCreateSuccess ( value : any ) {
223+ this . logService . info (
224+ `[Sponsorship] Organization created successfully: organizationId=${ value ?. organizationId } ` ,
225+ ) ;
195226 // Use newly created organization id
196227 await this . doSubmit ( value . organizationId ) ;
197228 }
0 commit comments