Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Reading exception message while sending message using Twilio API

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 484
    Comment on it

    While using the Twilio APIs, we may get exceptions while sending the messages. i.e. If the phone number is not correct or twilio does not provide service in the recepient country or any other reason.

    In the case of exception, we must let the user know that some error has occurred and we must log the exact error for our reference also.

    Here is the sample code of getting twilio exception

    string errorMessage=string.Empty;  
    var twilio = new TwilioRestClient(twilioAccountSid, twilioAuthToken);
    string receipientPhoneNumber="00000";
    var responeMessage = twilio.SendMessage(twilioPhoneNumber, receipientPhoneNumber, "Hi");
                if (responeMessage.RestException != null)
                {
                    errorMessage = responeMessage .RestException.Message;
                }

    In above sample we are trying to send message to phone number 00000 which is not a valid number. Twilio returns the error in response of sendMessage method.

    We can check if the error has occurred or not by checking the RestException object of response which holds the propery Message which is the error message sent by Twilio

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: