Why are AngularJS $http success/error methods deprecated? Removed from v1.6?

AngularjsAngularjs HttpAngularjs 1.6

Angularjs Problem Overview


The AngularJS documentation has a Deprecation Notice for the $http success and error methods. Is there a specific reason this abstraction was removed from the library?

Angularjs Solutions


Solution 1 - Angularjs

The problem was that .success and .error methods are not chainable because they ignore return values. This caused problems for people familiar with chaining and encouraged poor code from people unfamiliar with chaining. Witness all the examples on StackOverflow that use the deferred anti-pattern.

To quote one of the AngularJS team: >IMO .success and .error were a bad bit of API design in the first place. This issue highlights a number of situations where developers get confused because they either expect .success and .error to work the same way as .then or vice versa. In a perfect world I would rather just ditch these $http specific "promises". Instead we could encourage developers to use the standard $q promise API .then and .catch. There is very little benefit IMO in working with explicit parameters over working with the response object.

>ā€” AngularJS Issue #10508 $http .success/.error dissimilar from how .then works.

>Deprecation Notice (v1.5) >-- >The $http legacy promise methods success and error have been deprecated. Use the standard then method instead. If $httpProvider.useLegacyPromiseExtensions is set to false then these methods will throw $http/legacy error.

>ā€” AngularJS $http Service API Reference -- deprecation notice

Solution 2 - Angularjs

The pattern that javascript it using related to promises is only with .then(successCallback, errorCallback), so they are probably aiming to use js pattern.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionphiloniareView Question on Stackoverflow
Solution 1 - AngularjsgeorgeawgView Answer on Stackoverflow
Solution 2 - AngularjsIgor SantanaView Answer on Stackoverflow