Skip to content

Commit

Permalink
[core-http] Fix the error inconsistency of requestOptions.timeout - n…
Browse files Browse the repository at this point in the history
…ode vs browser (#7159)

* fix the timeout inconsistency of requestOptions.timeout

* document the error

* added changelog

* update changelog

* Update sdk/core/core-http/lib/webResource.ts

Co-Authored-By: Ramya Rao <[email protected]>

* Update sdk/core/core-http/CHANGELOG.md

Co-Authored-By: Ramya Rao <[email protected]>

Co-authored-by: Ramya Rao <[email protected]>
  • Loading branch information
HarshaNalluru and ramya-rao-a authored Feb 4, 2020
1 parent 084c40f commit e8860be
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
1 change: 1 addition & 0 deletions sdk/core/core-http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.0.4 (Unreleased)

- When an operation times out based on the `timeout` configured in the `OperationRequestOptions`, it gets terminated with an error. In this update, the error that is thrown in browser for such cases is updated to match what is thrown in node i.e an `AbortError` is thrown instead of the previous `RestError`. [PR #7159](https://github.com/Azure/azure-sdk-for-js/pull/7159)
- Fixed an issue where `error.code` and `error.message` are not assigned for `StorageError` instances. ([PR #7107](https://github.com/Azure/azure-sdk-for-js/pull/7107))

## 1.0.3 (2020-01-02)
Expand Down
1 change: 1 addition & 0 deletions sdk/core/core-http/lib/webResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ export interface RequestOptionsBase {

/**
* The number of milliseconds a request can take before automatically being terminated.
* If the request is terminated, an `AbortError` is thrown.
*/
timeout?: number;

Expand Down
14 changes: 3 additions & 11 deletions sdk/core/core-http/lib/xhrHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,7 @@ function rejectOnTerminalEvent(
)
)
);
xhr.addEventListener("abort", () => reject(new AbortError("The operation was aborted.")));
xhr.addEventListener("timeout", () =>
reject(
new RestError(
`timeout of ${xhr.timeout}ms exceeded`,
RestError.REQUEST_SEND_ERROR,
undefined,
request
)
)
);
const abortError = new AbortError("The operation was aborted.");
xhr.addEventListener("abort", () => reject(abortError));
xhr.addEventListener("timeout", () => reject(abortError));
}

0 comments on commit e8860be

Please sign in to comment.