From 1e56c89f5984ce38d78b9a3f8d33e63e8fc5c72b Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 13 Jun 2022 11:34:59 -0400 Subject: [PATCH] Handle custom error messages from API --- .../verification/steps/sms-verification.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/soapbox/features/verification/steps/sms-verification.tsx b/app/soapbox/features/verification/steps/sms-verification.tsx index 6e26050dd..a4017f061 100644 --- a/app/soapbox/features/verification/steps/sms-verification.tsx +++ b/app/soapbox/features/verification/steps/sms-verification.tsx @@ -1,3 +1,4 @@ +import { AxiosError } from 'axios'; import React from 'react'; import { useIntl } from 'react-intl'; import OtpInput from 'react-otp-input'; @@ -61,15 +62,13 @@ const SmsVerification = () => { ), ); setStatus(Statuses.REQUESTED); - }).catch(() => { - dispatch( - snackbar.error( - intl.formatMessage({ - id: 'sms_verification.fail', - defaultMessage: 'Failed to send SMS message to your phone number.', - }), - ), - ); + }).catch((error: AxiosError) => { + const message = (error.response?.data as any)?.message || intl.formatMessage({ + id: 'sms_verification.fail', + defaultMessage: 'Failed to send SMS message to your phone number.', + }); + + dispatch(snackbar.error(message)); setStatus(Statuses.FAIL); }); }, [phone, isValid]);