Skip to content

Commit

Permalink
fix: check if 'lineTypeIntelligence' property exists (#3758)
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard authored Dec 28, 2023
1 parent 8ce9ff4 commit 3eb3ed3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/api/src/domain/phone-provider/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
4 changes: 4 additions & 0 deletions core/api/src/graphql/error-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
4 changes: 4 additions & 0 deletions core/api/src/services/twilio-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
InvalidOrApprovedVerificationError,
InvalidPhoneNumberPhoneProviderError,
InvalidTypePhoneProviderError,
MissingTypePhoneProviderError,
PhoneCodeInvalidError,
PhoneProviderConnectionError,
PhoneProviderRateLimitExceededError,
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 3eb3ed3

Please sign in to comment.