mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Deprecating success/error in favor of then/catch
This commit is contained in:
@@ -28,8 +28,23 @@ var axios = module.exports = function axios(config) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function deprecatedMethod(method, instead, docs) {
|
||||||
|
try {
|
||||||
|
console.warn(
|
||||||
|
'DEPRECATED method `' + method + '`.' +
|
||||||
|
(instead ? ' Use `' + instead + '` instead.' : '') +
|
||||||
|
' This method will be removed in a future release.');
|
||||||
|
|
||||||
|
if (docs) {
|
||||||
|
console.warn('For more information about usage see ' + docs);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
// Provide alias for success
|
// Provide alias for success
|
||||||
promise.success = function success(fn) {
|
promise.success = function success(fn) {
|
||||||
|
deprecatedMethod('success', 'then', 'https://github.com/mzabriskie/axios/blob/master/README.md#response-api');
|
||||||
|
|
||||||
promise.then(function(response) {
|
promise.then(function(response) {
|
||||||
fn(response.data, response.status, response.headers, response.config);
|
fn(response.data, response.status, response.headers, response.config);
|
||||||
});
|
});
|
||||||
@@ -38,6 +53,8 @@ var axios = module.exports = function axios(config) {
|
|||||||
|
|
||||||
// Provide alias for error
|
// Provide alias for error
|
||||||
promise.error = function error(fn) {
|
promise.error = function error(fn) {
|
||||||
|
deprecatedMethod('error', 'catch', 'https://github.com/mzabriskie/axios/blob/master/README.md#response-api');
|
||||||
|
|
||||||
promise.then(null, function(response) {
|
promise.then(null, function(response) {
|
||||||
fn(response.data, response.status, response.headers, response.config);
|
fn(response.data, response.status, response.headers, response.config);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user