Skip to content

Upgrade Error Handling Functionality #404

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

Closed
KaptenJon opened this issue Feb 21, 2017 · 13 comments
Closed

Upgrade Error Handling Functionality #404

KaptenJon opened this issue Feb 21, 2017 · 13 comments
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@KaptenJon
Copy link

KaptenJon commented Feb 21, 2017

Issue Summary

I override System.Net.ServicePointManager.ServerCertificateValidationCallback (in this case not in a good way) and sendgrids certificate was treated as a bad certificate. When I user SendGridClient it throws away the underlying exception replying with a HttpResponse OK leaving the developer with no clue. Using the nuget package makes it even harder though I can't step through the code.

I suggest to return an other http response statuscode and include the exception messege (maybe also inner exception message) with the returned response.

Steps to Reproduce

1 Override System.Net.ServicePointManager.ServerCertificateValidationCallback =
(sender, certificate, chain, errors) =>
{ return false;}
2. Use sendgridclient and see your ok message (but now send email)

Technical details:

@thinkingserious thinkingserious added status: help wanted requesting help from the community type: question question directed at the library labels Feb 21, 2017
@thinkingserious
Copy link
Contributor

Hello @KaptenJon,

Currently, you can retrieve the error messages as follows: https://github.com/sendgrid/sendgrid-csharp/blob/master/TROUBLESHOOTING.md#error and the status codes we return are: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html

Unfortunately, I'm not quite sure how to reproduce your error. I have not tried overriding System.Net.ServicePointManager.ServerCertificateValidationCallback. Do you mind providing some additional code so I can try to reproduce?

With Best Regards,

Elmer

@KaptenJon
Copy link
Author

KaptenJon commented Feb 22, 2017 via email

@thinkingserious
Copy link
Contributor

Hi @KaptenJon,

If there is an exception, we current include the exception message in the response content, like so: https://github.com/sendgrid/sendgrid-csharp/blob/master/src/SendGrid/SendGridClient.cs#L377, then you can access the error message like this: Console.WriteLine(response.Body.ReadAsStringAsync().Result);

Does that help?

@KaptenJon KaptenJon changed the title If you the connection for public class SendGridClient If you the connection for endGridClient fails Feb 23, 2017
@KaptenJon KaptenJon changed the title If you the connection for endGridClient fails If you the connection for sendGridClient fails Feb 23, 2017
@KaptenJon
Copy link
Author

KaptenJon commented Feb 23, 2017

Hi, I actually totally missed that reading the code :)
However it is not enough this is what the message in the exception say: "An error occurred while sending the request."
Thats very general, the inner message though: "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."
and next level even better...

And I also still think the status code shouldent be ok. I am not an expert in http responses but how about HttpStatusCode.Unauthorized

@KaptenJon KaptenJon changed the title If you the connection for sendGridClient fails If the connection for sendGridClient fails Feb 23, 2017
@KaptenJon
Copy link
Author

     response.Content = new StringContent(message + ex.Message + "\n\n" +ex.InnerException?.Message + "\n\n" + ex.InnerException?.InnerException?.Message);

@thinkingserious
Copy link
Contributor

Ah, thanks for the additional details!

We need to refactor our error handling. I will leave this ticket open to track the progress and I've added this to our backlog.

I'm changing the title of this issue to reflect it's new purpose.

Thanks!

@thinkingserious thinkingserious changed the title If the connection for sendGridClient fails Upgrade Error Handling Functionality Feb 23, 2017
@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap and removed type: question question directed at the library labels Feb 23, 2017
@KaptenJon
Copy link
Author

KaptenJon commented Feb 23, 2017 via email

@AElvik
Copy link

AElvik commented Mar 1, 2017

Error handling should not return OK if it isn't. I'd prefer if the exception was not caught so i could handle different cases in my code.

As a workaround I added some code that looks for ".NET HttpRequestException" or ".NET Exception" in the result if status is OK, then i consider it an exception and adds some retry.

@KaptenJon
Copy link
Author

KaptenJon commented Mar 1, 2017 via email

@thinkingserious
Copy link
Contributor

@AElvik,

I have added your vote to this issue to help increase the priority in our backlog. Thanks for taking the time to reach out :)

@AElvik
Copy link

AElvik commented Mar 2, 2017

@KaptenJon Will also need the dto classes, but that should not be to many so I'll try that
@thinkingserious Thanks

@thinkingserious
Copy link
Contributor

Hello everyone,

This issue has been resolved with: #434

@KaptenJon
Copy link
Author

KaptenJon commented Apr 13, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

3 participants