Exceptions when request should go through a proxy

I just noted that by default, the .NET SDK is made to use no proxy (unfortunately RestSharp seems different in that respect than HttpClient). If you make a request in an environment that needs a proxy, instead of getting a useful error back, you get a System.ArgumentException: 'Value cannot be null. (Parameter 'source')' bubbling up from AuthExtensions.CallTokenApi from this call

apiClient.Configuration.Logger.Trace(method.ToString(), url, postBody, statusCode, headerParams, response.Headers.Select(header => new { Name = header.GetType().GetProperty("Name").GetValue(header), Value = header.GetType().GetProperty("Value").GetValue(header) })
                        .ToDictionary(header => header.Name.ToString(), header => header.Value.ToString()));

if response.Headers is empty, you get the exception.

May I humbly request this (and the two subsequent logging lines that have the same issue) be rewritten to handle the case where response has no headers?

if I skip the logging code, I get a much more useful exception:

PureCloudPlatform.Client.V2.Client.ApiException: 'Error calling PostToken: The proxy tunnel request to proxy 'http://myproxy.com:8080/' failed with status code '407'."'

Now that's a lot more useful, no?

Hi @ssteiner

Did you try with latest versions of .NET sdk. That logging problem you mentioned is addressed already.

Best Regards
Hemanth

1 Like

ahh, I thought I had already updated the Nuget package - when I got the exception I went back to the source I downloaded with the first nuget.. and turns out I had never updated the Nuget package from 189 to 190. I see that it's indeed addressed when I look at the code in the Github repo.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.