Skip to content

Commit

Permalink
Fixes processing 429s from SPs (microsoft#2165)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankowitz authored Aug 19, 2021
1 parent ef41cce commit 7872ebb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public async Task HardDeleteAsync(ResourceKey key, bool keepCurrentVersion, Canc
}
catch (CosmosException exception)
{
if (exception.IsRequestEntityTooLarge())
if (exception.IsRequestRateExceeded())
{
throw;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public Task ProcessErrorResponse(ResponseMessage response)

public void ProcessErrorResponse(HttpStatusCode statusCode, Headers headers, string errorMessage)
{
if (statusCode == HttpStatusCode.TooManyRequests)
// Stored procedure statuses will be in the substatuscode
if (statusCode == HttpStatusCode.TooManyRequests || headers.GetSubStatusValue() == (int)HttpStatusCode.TooManyRequests)
{
string retryHeader = headers["x-ms-retry-after-ms"];
throw new RequestRateExceededException(int.TryParse(retryHeader, out int milliseconds) ? TimeSpan.FromMilliseconds(milliseconds) : null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* This stored procedure acquires list of available export jobs.
*
* This stored procedure acquires list of available export jobs.
*
* @constructor
* @param {string} maximumNumberOfConcurrentJobsAllowedInString - The maximum number of concurrent jobs allowed in string.
* @param {string} jobHeartbeatTimeoutThresholdInSecondsInString - The number of seconds allowed before the job is considered to be stale in string.
Expand Down Expand Up @@ -145,6 +145,6 @@ function acquireExportJobs(maximumNumberOfConcurrentJobsAllowedInString, jobHear
}

function throwTooManyRequestsError() {
throw new Error(ErrorCodes.RequestEntityTooLarge, `The request could not be completed.`);
throw new Error(429, `The request could not be completed.`);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* This stored procedure acquires list of available reindex jobs.
*
* This stored procedure acquires list of available reindex jobs.
*
* @constructor
* @param {string} maximumNumberOfConcurrentJobsAllowedInString - The maximum number of concurrent jobs allowed in string.
* @param {string} jobHeartbeatTimeoutThresholdInSecondsInString - The number of seconds allowed before the job is considered to be stale in string.
Expand Down Expand Up @@ -145,6 +145,6 @@ function acquireReindexJobs(maximumNumberOfConcurrentJobsAllowedInString, jobHea
}

function throwTooManyRequestsError() {
throw new Error(ErrorCodes.RequestEntityTooLarge, `The request could not be completed.`);
throw new Error(429, `The request could not be completed.`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ function hardDelete(resourceTypeName, resourceId, keepCurrentVersion) {
}

function throwTooManyRequestsError() {
throw new Error(ErrorCodes.RequestEntityTooLarge, `The request could not be completed.`);
throw new Error(429, `The request could not be completed.`);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* This stored procedure can be used to replace an existing document
*
*
* @constructor
* @param {any} doc - The CosmosResourceWrapper to save
* @param {string} matchVersionId - required etag to match against when replacing an existing document
Expand Down Expand Up @@ -81,7 +81,7 @@ function replaceSingleResource(doc, matchVersionId) {
}

function throwRequestNotQueuedError() {
throw new Error(503, "Request could not be queued.");
throw new Error(429, "Request could not be queued.");
}

function throwPreconditionFailedError() {
Expand Down

0 comments on commit 7872ebb

Please sign in to comment.