From 7685fb00abd12b048e2d3527733f29e4f7c4968b Mon Sep 17 00:00:00 2001 From: vindard <17693119+vindard@users.noreply.github.com> Date: Wed, 27 Dec 2023 12:48:49 -0400 Subject: [PATCH] fix: check if 'lineTypeIntelligence' property exists --- core/api/src/domain/phone-provider/errors.ts | 3 +++ core/api/src/graphql/error-map.ts | 4 ++++ core/api/src/services/twilio-service.ts | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/core/api/src/domain/phone-provider/errors.ts b/core/api/src/domain/phone-provider/errors.ts index ca4dd0f947..eaa857b171 100644 --- a/core/api/src/domain/phone-provider/errors.ts +++ b/core/api/src/domain/phone-provider/errors.ts @@ -10,6 +10,9 @@ export class RestrictedRegionPhoneProviderError extends PhoneProviderServiceErro export class UnsubscribedRecipientPhoneProviderError extends PhoneProviderServiceError {} export class RestrictedRecipientPhoneNumberError extends PhoneProviderServiceError {} export class InvalidOrApprovedVerificationError extends PhoneProviderServiceError {} +export class MissingTypePhoneProviderError extends PhoneProviderServiceError { + level = ErrorLevel.Critical +} export class PhoneCodeInvalidError extends PhoneProviderServiceError {} diff --git a/core/api/src/graphql/error-map.ts b/core/api/src/graphql/error-map.ts index 05e0ce7d7d..4ffaa62464 100644 --- a/core/api/src/graphql/error-map.ts +++ b/core/api/src/graphql/error-map.ts @@ -179,6 +179,10 @@ export const mapError = (error: ApplicationError): CustomGraphQLError => { message = "Invalid phone number type. Please use a mobile number." return new ValidationInternalError({ message, logger: baseLogger }) + case "MissingTypePhoneProviderError": + message = "Issue checking phone number. Please try again later or contact support." + return new ValidationInternalError({ message, logger: baseLogger }) + case "RestrictedRegionPhoneProviderError": message = "Phone number is not from a valid region" return new ValidationInternalError({ message, logger: baseLogger }) diff --git a/core/api/src/services/twilio-service.ts b/core/api/src/services/twilio-service.ts index 6352005640..e54e8a4e4c 100644 --- a/core/api/src/services/twilio-service.ts +++ b/core/api/src/services/twilio-service.ts @@ -16,6 +16,7 @@ import { InvalidOrApprovedVerificationError, InvalidPhoneNumberPhoneProviderError, InvalidTypePhoneProviderError, + MissingTypePhoneProviderError, PhoneCodeInvalidError, PhoneProviderConnectionError, PhoneProviderRateLimitExceededError, @@ -57,6 +58,9 @@ export const TwilioClient = (): IPhoneProviderService => { fields: "line_type_intelligence", }) // https://www.twilio.com/docs/lookup/v2-api/line-type-intelligence#type-property-values + if (!lookup.lineTypeIntelligence) { + return new MissingTypePhoneProviderError() + } if (lookup.lineTypeIntelligence.type === "nonFixedVoip") { return new InvalidTypePhoneProviderError("nonFixedVoip") }