Skip to content

Commit

Permalink
add 204 poll state for post
Browse files Browse the repository at this point in the history
  • Loading branch information
Qinyuan Wan committed Apr 7, 2016
1 parent 9573dee commit b9d642d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn
return callback(err);
});
} else if (pollingState.locationHeaderLink) {
self._updateStateFromLocationHeader(pollingState, function(err) {
self._updateStateFromLocationHeader(resultOfInitialRequest.request.method, pollingState, function(err) {
return callback(err);
});
} else if (resultOfInitialRequest.request.method === 'PUT') {
Expand Down Expand Up @@ -194,7 +194,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf
return callback(err);
});
} else if (pollingState.locationHeaderLink) {
self._updateStateFromLocationHeader(pollingState, function(err) {
self._updateStateFromLocationHeader(resultOfInitialRequest.request.method, pollingState, function(err) {
return callback(err);
});
} else if (resultOfInitialRequest.request.method === 'PUT') {
Expand Down Expand Up @@ -223,10 +223,11 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf
};

AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = function (initialRequest) {
if (initialRequest.response.statusCode === 200 ||
initialRequest.response.statusCode === 202 ||
(initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') ||
(initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) {
var statusCode = initialRequest.response.statusCode;
var method = initialRequest.request.method;
if (statusCode === 200 || statusCode === 202 ||
(statusCode === 201 && method === 'PUT') ||
(statusCode === 204 && (method === 'DELETE' || method === 'POST'))) {
return false;
} else {
return true;
Expand Down Expand Up @@ -263,7 +264,7 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio
* Retrieve PUT operation status by polling from 'location' header.
* @param {object} [pollingState] - The object to persist current operation state.
*/
AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingState, callback) {
AzureServiceClient.prototype._updateStateFromLocationHeader = function (method, pollingState, callback) {
this._getStatus(pollingState.locationHeaderLink, function(err, result) {
if (err) return callback(err);

Expand All @@ -274,8 +275,8 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingS
if (statusCode === 202) {
pollingState.status = LroStates.InProgress;
} else if (statusCode === 200 ||
(statusCode === 201 && pollingState.request.method === 'PUT') ||
(statusCode === 204 && pollingState.request.method === 'DELETE')) {
(statusCode === 201 && method === 'PUT') ||
(statusCode === 204 && (method === 'DELETE' || method === 'POST'))) {

pollingState.status = LroStates.Succeeded;

Expand All @@ -284,7 +285,9 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingS
message: util.format('Long running operation failed with status \'%s\'.', pollingState.status)
};
pollingState.resource = result.body;
}
} else {
return callback(new Error('The response from long running operation does not have a valid status code.'));
}
callback(null);
});
};
Expand Down

0 comments on commit b9d642d

Please sign in to comment.