Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One or more errors occurred. (HTTP Response Not OK) using .net core #15

Open
jadav1982 opened this issue May 11, 2021 · 2 comments
Open

Comments

@jadav1982
Copy link

jadav1982 commented May 11, 2021

Hello,

I have create console application using .net core 3.

Code

        String API_KEY = "my user name";
        String API_SECRET = "my password";
        Boolean HMAC = false;
        MessageMediaMessagesClient client = new MessageMediaMessagesClient(API_KEY, API_SECRET, HMAC);

        MessagesController messages = client.Messages;


        SendMessagesRequest body = new SendMessagesRequest();
        body.Messages = new List<Message>();

        Message body_messages_0 = new Message();
        body_messages_0.Content = "Test SMS from Tarun";
        body_messages_0.DestinationNumber = "+16233266836";
        body.Messages.Add(body_messages_0);

        try
        {
            MessageMedia.Messages.Models.SendMessagesResponse result = messages.SendMessagesAsync(body).Result;
            Console.WriteLine(result);
        }
        catch (APIException e)
        {
            Console.WriteLine(e.Message + e.ResponseCode + e.HttpContext.ToString());
        };

Getting below error

System.AggregateException HResult=0x80131500 Message=One or more errors occurred. (HTTP Response Not OK) Source=System.Private.CoreLib StackTrace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at ConsoleApp4.Program.Main(String[] args) in C:\Users\Tarun\source\repos\ConsoleApp4\ConsoleApp4\Program.cs:line 45

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
APIException: HTTP Response Not OK
`

@maqsoodahmad
Copy link

Did you get any fix for this issue. I'm also getting same when trying this

@AaronCoad
Copy link

@jadav1982 and @maqsoodahmad, while I'm not involved in the development of this, I might be able to assist / advise. If either of you are still having issues try replacing the catch block with:

 catch (AggregateException e)
 {
     foreach (Exception exception in e.InnerExceptions)
     {
         if (exception.GetType() == typeof(APIException))
             Console.WriteLine(String.Format("{0}; {1};",(exception as APIException).Message, (exception as APIException).ResponseCode));
     }
 };

The example provided in the ReadMe isn't correct and results in an Unhandled Exception (Tasks throw AggregateExceptions) and you lose the content of the APIException which should have the Response Code in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants