-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Line 390 in c5954d2
| httpResponseHeaders = response.Headers.ToList<Parameter>(); |
When the ApiClient encounters a network-level failure (e.g., inability to connect to the host, DNS failure, or timeout), the actualRestClient.Execute(request) returns a response where the Headers property is null.
Currently, CallApi attempts to call response.Headers.ToList() immediately. Because Headers is null, this throws a System.ArgumentNullException: Value cannot be null. (Parameter 'source') instead of allowing the user to handle the actual network error or status code.
Steps to Reproduce
- Initialize the ApiClient with an invalid base path or disconnect from the network.
- Call any API method (e.g., PaymentsApi.CreatePayment).
- The SDK throws System.ArgumentNullException during the logging/processing phase of the response.
Stack Trace
System.ArgumentNullException: Value cannot be null. (Parameter 'source').
ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
Enumerable.ToList[TSource](IEnumerable1 source) ApiClient.CallApi(String path, Method method, Dictionary2 queryParams, Object postBody, Dictionary2 headerParams, Dictionary2 formParams, Dictionary2 fileParams, Dictionary2 pathParams, String contentType, Boolean isResponseMLEForApi)
PaymentsApi.CreatePaymentWithHttpInfo(CreatePaymentRequest createPaymentRequest)
PaymentsApi.CreatePayment(CreatePaymentRequest createPaymentRequest)
Proposed Fix
Add a null check (null-coalescing operator) when assigning httpResponseHeaders to ensure the collection is at least an empty list if the connection failed.
httpResponseHeaders = response.Headers?.ToList<Parameter>() ?? new List<Parameter>();