|
2 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
|
5 | | -import { Injectable } from '@nestjs/common'; |
| 5 | +import { Inject, Injectable, LoggerService } from '@nestjs/common'; |
6 | 6 | import { SmsManager } from './sms.manager'; |
7 | 7 | import { OtpManager } from '@fxa/shared/otp'; |
8 | 8 | import { RecoveryPhoneConfig } from './recovery-phone.service.config'; |
9 | | -import { RecoveryPhoneManager } from './recovery-phone.manager'; |
| 9 | +import { |
| 10 | + PhoneNumberLookupData, |
| 11 | + RecoveryPhoneManager, |
| 12 | +} from './recovery-phone.manager'; |
10 | 13 | import { |
11 | 14 | RecoveryNumberNotExistsError, |
12 | 15 | RecoveryNumberNotSupportedError, |
13 | 16 | RecoveryPhoneNotEnabled, |
14 | 17 | RecoveryNumberRemoveMissingBackupCodes, |
15 | 18 | } from './recovery-phone.errors'; |
16 | 19 | import { MessageInstance } from 'twilio/lib/rest/api/v2010/account/message'; |
| 20 | +import { LOGGER_PROVIDER } from '@fxa/shared/log'; |
17 | 21 |
|
18 | 22 | @Injectable() |
19 | 23 | export class RecoveryPhoneService { |
20 | 24 | constructor( |
21 | 25 | private readonly recoveryPhoneManager: RecoveryPhoneManager, |
22 | 26 | private readonly smsManager: SmsManager, |
23 | 27 | private readonly otpCode: OtpManager, |
24 | | - private readonly config: RecoveryPhoneConfig |
| 28 | + private readonly config: RecoveryPhoneConfig, |
| 29 | + @Inject(LOGGER_PROVIDER) private readonly log?: LoggerService |
25 | 30 | ) {} |
26 | 31 |
|
27 | 32 | /** |
@@ -125,9 +130,16 @@ export class RecoveryPhoneService { |
125 | 130 | } |
126 | 131 |
|
127 | 132 | // If this was for a setup operation. Register the phone number to the uid. |
128 | | - const lookupData = await this.smsManager.phoneNumberLookup( |
129 | | - data.phoneNumber |
130 | | - ); |
| 133 | + const lookupData: PhoneNumberLookupData = await (async () => { |
| 134 | + try { |
| 135 | + return await this.smsManager.phoneNumberLookup(data.phoneNumber); |
| 136 | + } catch (error) { |
| 137 | + this.log?.error('RecoveryPhoneService.confirmSetupCode', error); |
| 138 | + |
| 139 | + throw new RecoveryNumberNotSupportedError(data.phoneNumber, error); |
| 140 | + } |
| 141 | + })(); |
| 142 | + |
131 | 143 | await this.recoveryPhoneManager.registerPhoneNumber( |
132 | 144 | uid, |
133 | 145 | data.phoneNumber, |
|
0 commit comments