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

Commit c5e0890

Browse files
committed
feat($http): remove deprecated callback methods: success()/error()
BREAKING CHANGE: `$http`'s deprecated callback methods `success()` and `error()` have been removed. Use the standard `then()`/`catch()` promise methods instead. (Note that the method signatures are different.) Before: ```js $http(...).success(function (data, status, headers, config) { ... })); $http(...).error(function (data, status, headers, config) { ... })); ``` After: ```js $http(...).then(function (response) { var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... })); $http(...).catch(function (response) { var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... })); ```
1 parent 16dccea commit c5e0890

File tree

3 files changed

+93
-330
lines changed

3 files changed

+93
-330
lines changed

docs/content/error/$http/legacy.ngdoc

-45
This file was deleted.

src/ng/http.js

-61
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ var JSON_ENDS = {
88
'{': /}$/
99
};
1010
var JSON_PROTECTION_PREFIX = /^\)\]\}',?\n/;
11-
var $httpMinErr = minErr('$http');
12-
var $httpMinErrLegacyFn = function(method) {
13-
return function() {
14-
throw $httpMinErr('legacy', 'The method `{0}` on the promise returned from `$http` has been disabled.', method);
15-
};
16-
};
1711

1812
function serializeValue(v) {
1913
if (isObject(v)) {
@@ -340,30 +334,6 @@ function $HttpProvider() {
340334
return useApplyAsync;
341335
};
342336

343-
var useLegacyPromise = true;
344-
/**
345-
* @ngdoc method
346-
* @name $httpProvider#useLegacyPromiseExtensions
347-
* @description
348-
*
349-
* Configure `$http` service to return promises without the shorthand methods `success` and `error`.
350-
* This should be used to make sure that applications work without these methods.
351-
*
352-
* Defaults to true. If no value is specified, returns the current configured value.
353-
*
354-
* @param {boolean=} value If true, `$http` will return a promise with the deprecated legacy `success` and `error` methods.
355-
*
356-
* @returns {boolean|Object} If a value is specified, returns the $httpProvider for chaining.
357-
* otherwise, returns the current configured value.
358-
**/
359-
this.useLegacyPromiseExtensions = function(value) {
360-
if (isDefined(value)) {
361-
useLegacyPromise = !!value;
362-
return this;
363-
}
364-
return useLegacyPromise;
365-
};
366-
367337
/**
368338
* @ngdoc property
369339
* @name $httpProvider#interceptors
@@ -497,14 +467,6 @@ function $HttpProvider() {
497467
* $httpBackend.flush();
498468
* ```
499469
*
500-
* ## Deprecation Notice
501-
* <div class="alert alert-danger">
502-
* The `$http` legacy promise methods `success` and `error` have been deprecated.
503-
* Use the standard `then` method instead.
504-
* If {@link $httpProvider#useLegacyPromiseExtensions `$httpProvider.useLegacyPromiseExtensions`} is set to
505-
* `false` then these methods will throw {@link $http:legacy `$http/legacy`} error.
506-
* </div>
507-
*
508470
* ## Setting HTTP Headers
509471
*
510472
* The $http service will automatically add certain HTTP headers to all requests. These defaults
@@ -985,29 +947,6 @@ function $HttpProvider() {
985947
promise = chainInterceptors(promise, responseInterceptors);
986948
promise = promise.finally(completeOutstandingRequest);
987949

988-
if (useLegacyPromise) {
989-
promise.success = function(fn) {
990-
assertArgFn(fn, 'fn');
991-
992-
promise.then(function(response) {
993-
fn(response.data, response.status, response.headers, config);
994-
});
995-
return promise;
996-
};
997-
998-
promise.error = function(fn) {
999-
assertArgFn(fn, 'fn');
1000-
1001-
promise.then(null, function(response) {
1002-
fn(response.data, response.status, response.headers, config);
1003-
});
1004-
return promise;
1005-
};
1006-
} else {
1007-
promise.success = $httpMinErrLegacyFn('success');
1008-
promise.error = $httpMinErrLegacyFn('error');
1009-
}
1010-
1011950
return promise;
1012951

1013952

0 commit comments

Comments
 (0)