From 37378651533c19dbdc1c22c9d958143d3b4ca794 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 12 Sep 2024 12:30:19 -0700 Subject: [PATCH] add try/except --- app/clients/pinpoint/aws_pinpoint.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/clients/pinpoint/aws_pinpoint.py b/app/clients/pinpoint/aws_pinpoint.py index 186b5f9b4..aa454630a 100644 --- a/app/clients/pinpoint/aws_pinpoint.py +++ b/app/clients/pinpoint/aws_pinpoint.py @@ -1,4 +1,5 @@ from boto3 import client +from botocore.exceptions import ClientError from flask import current_app from app.clients import AWS_CLIENT_CONFIG, Client @@ -25,13 +26,19 @@ class AwsPinpointClient(Client): return "pinpoint" def validate_phone_number(self, country_code, phone_number): - response = self._client.phone_number_validate( - NumberValidateRequest={"IsoCountryCode": country_code, "PhoneNumber": phone_number} - ) + try: + response = self._client.phone_number_validate( + NumberValidateRequest={ + "IsoCountryCode": country_code, + "PhoneNumber": phone_number, + } + ) - # TODO right now this will only print with AWS simulated numbers, - # but remove this when that changes - current_app.logger.info(hilite(response)) + # TODO right now this will only print with AWS simulated numbers, + # but remove this when that changes + current_app.logger.info(hilite(response)) + except ClientError: + current_app.logger.exception("Could not validate with pinpoint") # TODO This is the structure of the response. When the phone validation # capability we want to offer is better defined (it may just be a question