-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($http): remove deprecated callback methods: success()/error()
#15157
feat($http): remove deprecated callback methods: success()/error()
#15157
Conversation
Were all docs updated when this feature was deprecated? Otherwise we'd have to check that. |
Good point. I saw there were docs updates in #12112, so I assumed all docs were updated. |
LGTM. |
Yes and no. I don't specifically advise using Pedantically speaking, So, while I didn't mean to explicitly advice people replacing But I don't feel strongly about it. If you have concerns about the implications of that, I would be happy to discuss 😃 Did you talk about the consequences in the meeting? We rarely removed deprecated features. What's the consensus on the impact of this change? We didn't talk much about it. We just agreed it is time for this long-deprecated API to go. BTW, it is not true that we haven't removed other deprecated stuff before (don't judge by I'll leave this unmerged for the time being and let's revisit on the next meeting to make sure we didn't miss anything. |
BREAKING CHANGE: `$http`'s deprecated custom callback methods - `success()` and `error()` - have been removed. You can use the standard `then()`/`catch()` promise methods instead, but note that the method signatures and return values are different. `success(fn)` can be replaced with `then(fn)`, and `error(fn)` can be replaced with either `then(null, fn)` or `catch(fn)`. Before: ```js $http(...). success(function onSuccess(data, status, headers, config) { // Handle success ... }). error(function onError(data, status, headers, config) { // Handle error ... }); ``` After: ```js $http(...). then(function onSuccess(response) { // Handle success var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... }, function onError(response) { // Handle error var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... }); // or $http(...). then(function onSuccess(response) { // Handle success var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... }). catch(function onError(response) { // Handle error var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... }); ``` **Note:** There is a subtle difference between the variations showed above. When using `$http(...).success(onSuccess).error(onError)` or `$http(...).then(onSuccess, onError)`, the `onError()` callback will only handle errors/rejections produced by the `$http()` call. If the `onSuccess()` callback produces an error/rejection, it won't be handled by `onError()` and might go unnoticed. In contrast, when using `$http(...).then(onSuccess).catch(onError)`, `onError()` will handle errors/rejections produced by both `$http()` _and_ `onSuccess()`.
5027b09
to
462cb12
Compare
Closes angular#15157 BREAKING CHANGE: `$http`'s deprecated custom callback methods - `success()` and `error()` - have been removed. You can use the standard `then()`/`catch()` promise methods instead, but note that the method signatures and return values are different. `success(fn)` can be replaced with `then(fn)`, and `error(fn)` can be replaced with either `then(null, fn)` or `catch(fn)`. Before: ```js $http(...). success(function onSuccess(data, status, headers, config) { // Handle success ... }). error(function onError(data, status, headers, config) { // Handle error ... }); ``` After: ```js $http(...). then(function onSuccess(response) { // Handle success var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... }, function onError(response) { // Handle error var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... }); // or $http(...). then(function onSuccess(response) { // Handle success var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... }). catch(function onError(response) { // Handle error var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... }); ``` **Note:** There is a subtle difference between the variations showed above. When using `$http(...).success(onSuccess).error(onError)` or `$http(...).then(onSuccess, onError)`, the `onError()` callback will only handle errors/rejections produced by the `$http()` call. If the `onSuccess()` callback produces an error/rejection, it won't be handled by `onError()` and might go unnoticed. In contrast, when using `$http(...).then(onSuccess).catch(onError)`, `onError()` will handle errors/rejections produced by both `$http()` _and_ `onSuccess()`.
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Feature removal (refactor but with a breaking change).
What is the current behavior? (You can also link to an open issue here)
The promises returned by
$http
have additions, non-standard methods:success()
,error()
. They have beed deprecated since v1.4.4 (#12112).Although there was a switch to disable them (
$httpProvider.useLegacyPromiseExtensions()
), they were enabled by default.What is the new behavior (if this is a feature change)?
success()
anderror()
are gone. Use the standardthen()
/catch()
promise methods instead.Does this PR introduce a breaking change?
Yes.
Please check if the PR fulfills these requirements
Other information: