WindowsAzure/azure-sdk-for-node — Issue #103: ServiceClient._performRequest does not handle request-level errors
Author: malyn
Created: 2012-02-25 05:26:31+00:00
State: open

ServiceClient._performRequest only expects errors to be generated during the response phase of the HTTP request, but the request phase can throw errors as well. I find that 'connect ETIMEDOUT' errors are fairly common and at the moment the SDK causes those errors to be surfaced as unhandled exceptions.

I believe that ServiceClient._performRequest should capture errors generated by the request object and return those to the callback method.

I was able to resolve this issue by adding the following block of code before the "// Pipe request body" section of serviceclient.js:

request = http.request(finalRequestOptions, processResponse);
}

>>>>> NEW CODE
// Handle request-level errors
request.on('error', function (err) {
var responseObject = { error: err.message };
callback(responseObject, function (finalResponseObject, finalCallback) {
finalCallback(finalResponseObject);
});
});
<<<<< NEW CODE

// Pipe request body
if (body && body.outputData) {

That may or may not be the correct fix -- it was unclear if I needed to apply any of the self.filter logic before returning to the caller, for example. That block of code does work fine in my test app though.