Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9a7ff07

Browse files
committed
fixup! fix($http): correct behavior
1 parent 4d82206 commit 9a7ff07

File tree

1 file changed

+56
-37
lines changed

1 file changed

+56
-37
lines changed

src/ng/http.js

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,9 @@ function $HttpProvider() {
437437
*
438438
* ## General usage
439439
* The `$http` service is a function which takes a single argument — a {@link $http#usage configuration object} —
440-
* that is used to generate an HTTP request and returns a {@link ng.$q promise}.
440+
* that is used to generate an HTTP request and returns a {@link ng.$q promise} that is
441+
* resolved (request success) or rejected (request failure) with a
442+
* {@link ng.$http#$http-returns response} object.
441443
*
442444
* ```js
443445
* // Simple GET request example:
@@ -453,24 +455,6 @@ function $HttpProvider() {
453455
* });
454456
* ```
455457
*
456-
* The response object has these properties:
457-
*
458-
* - **data** – `{string|Object}` – The response body transformed with the transform
459-
* functions.
460-
* - **status** – `{number}` – HTTP status code of the response.
461-
* - **headers** – `{function([headerName])}` – Header getter function.
462-
* - **config** – `{Object}` – The configuration object that was used to generate the request.
463-
* - **statusText** – `{string}` – HTTP status text of the response.
464-
* - **xhrStatus** – `{string}` – Status of the XMLHttpRequest (`complete`, `error`, `timeout` or `abort`).
465-
*
466-
* A response status code between 200 and 299 is considered a success status and will result in
467-
* the success callback being called. Any response status code outside of that range is
468-
* considered an error status and will result in the error callback being called.
469-
* Also, status codes less than -1 are normalized to zero. -1 usually means the request was
470-
* aborted, e.g. using a `config.timeout`.
471-
* Note that if the response is a redirect, XMLHttpRequest will transparently follow it, meaning
472-
* that the outcome (success or error) will be determined by the final response status code.
473-
*
474458
*
475459
* ## Shortcut methods
476460
*
@@ -845,16 +829,44 @@ function $HttpProvider() {
845829
* See {@link $http#caching $http Caching} for more information.
846830
* - **timeout** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise}
847831
* that should abort the request when resolved.
848-
* A numerical timeout or `$timeout` will set `xhrStatus` "timeout", and a resolved promise
849-
* will set it to "abort", following standard XMLHttpRequest behavior.
832+
*
833+
* A numerical timeout or a promise returned from {@link ng.$timeout $timeout}, will set
834+
* the `xhrStatus` in the {@link $http#$http-returns response} to "timeout", and any other
835+
* resolved promise will set it to "abort", following standard XMLHttpRequest behavior.
836+
*
850837
* - **withCredentials** - `{boolean}` - whether to set the `withCredentials` flag on the
851838
* XHR object. See [requests with credentials](https://developer.mozilla.org/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials)
852839
* for more information.
853840
* - **responseType** - `{string}` - see
854841
* [XMLHttpRequest.responseType](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#xmlhttprequest-responsetype).
855842
*
856-
* @returns {HttpPromise} Returns a {@link ng.$q `Promise}` that will be resolved to a response object
857-
* when the request succeeds or fails.
843+
* @returns {HttpPromise} A {@link ng.$q `Promise}` that will be resolved (request success)
844+
* or rejected (request failure) with a response object.
845+
*
846+
* The response object has these properties:
847+
*
848+
* - **data** – `{string|Object}` – The response body transformed with
849+
* the transform functions.
850+
* - **status** – `{number}` – HTTP status code of the response.
851+
* - **headers** – `{function([headerName])}` – Header getter function.
852+
* - **config** – `{Object}` – The configuration object that was used
853+
* to generate the request.
854+
* - **statusText** – `{string}` – HTTP status text of the response.
855+
* - **xhrStatus** – `{string}` – Status of the XMLHttpRequest
856+
* (`complete`, `error`, `timeout` or `abort`).
857+
*
858+
*
859+
* A response status code between 200 and 299 is considered a success status
860+
* and will result in the success callback being called. Any response status
861+
* code outside of that range is considered an error status and will result
862+
* in the error callback being called.
863+
* Also, status codes less than -1 are normalized to zero. -1 usually means
864+
* the request was aborted, e.g. using a `config.timeout`. More information
865+
* about the status might be available in the `xhrStatus` property.
866+
*
867+
* Note that if the response is a redirect, XMLHttpRequest will transparently
868+
* follow it, meaning that the outcome (success or error) will be determined
869+
* by the final response status code.
858870
*
859871
*
860872
* @property {Array.<Object>} pendingRequests Array of config objects for currently pending
@@ -1104,8 +1116,9 @@ function $HttpProvider() {
11041116
*
11051117
* @param {string|TrustedObject} url Absolute or relative URL of the resource that is being requested;
11061118
* or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1107-
* @param {Object=} config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1108-
* @returns {HttpPromise} Future object
1119+
* @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1120+
* @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
1121+
* See {@link ng.$http#$http-returns `$http()` return value}.
11091122
*/
11101123

11111124
/**
@@ -1117,8 +1130,9 @@ function $HttpProvider() {
11171130
*
11181131
* @param {string|TrustedObject} url Absolute or relative URL of the resource that is being requested;
11191132
* or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1120-
* @param {Object=} config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1121-
* @returns {HttpPromise} Future object
1133+
* @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1134+
* @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
1135+
* See {@link ng.$http#$http-returns `$http()` return value}.
11221136
*/
11231137

11241138
/**
@@ -1130,8 +1144,9 @@ function $HttpProvider() {
11301144
*
11311145
* @param {string|TrustedObject} url Absolute or relative URL of the resource that is being requested;
11321146
* or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1133-
* @param {Object=} config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1134-
* @returns {HttpPromise} Future object
1147+
* @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1148+
* @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
1149+
* See {@link ng.$http#$http-returns `$http()` return value}.
11351150
*/
11361151

11371152
/**
@@ -1172,8 +1187,9 @@ function $HttpProvider() {
11721187
*
11731188
* @param {string|TrustedObject} url Absolute or relative URL of the resource that is being requested;
11741189
* or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1175-
* @param {Object=} config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1176-
* @returns {HttpPromise} Future object
1190+
* @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1191+
* @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
1192+
* See {@link ng.$http#$http-returns `$http()` return value}.
11771193
*/
11781194
createShortMethods('get', 'delete', 'head', 'jsonp');
11791195

@@ -1186,8 +1202,9 @@ function $HttpProvider() {
11861202
*
11871203
* @param {string} url Relative or absolute URL specifying the destination of the request
11881204
* @param {*} data Request content
1189-
* @param {Object=} config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1190-
* @returns {HttpPromise} Future object
1205+
* @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1206+
* @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
1207+
* See {@link ng.$http#$http-returns `$http()` return value}.
11911208
*/
11921209

11931210
/**
@@ -1199,8 +1216,9 @@ function $HttpProvider() {
11991216
*
12001217
* @param {string} url Relative or absolute URL specifying the destination of the request
12011218
* @param {*} data Request content
1202-
* @param {Object=} config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1203-
* @returns {HttpPromise} Future object
1219+
* @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1220+
* @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
1221+
* See {@link ng.$http#$http-returns `$http()` return value}.
12041222
*/
12051223

12061224
/**
@@ -1212,8 +1230,9 @@ function $HttpProvider() {
12121230
*
12131231
* @param {string} url Relative or absolute URL specifying the destination of the request
12141232
* @param {*} data Request content
1215-
* @param {Object=} config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1216-
* @returns {HttpPromise} Future object
1233+
* @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1234+
* @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
1235+
* See {@link ng.$http#$http-returns `$http()` return value}.
12171236
*/
12181237
createShortMethodsWithData('post', 'put', 'patch');
12191238

0 commit comments

Comments
 (0)