Skip to content

Commit 9a26455

Browse files
author
周琳
committed
fix: promise error handler
1 parent 09cff3a commit 9a26455

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ function aopPromise(commit, loading, fn) {
7474
}
7575
return (...arg) => {
7676
let promise = Promise.resolve(loading)
77-
let chain = [showLoading, undefined, fn.bind(null, ...arg), undefined, hideLoading, hideLoading]
77+
let chain = [showLoading, undefined, fn.bind(null, ...arg), undefined, hideLoading, function (error) {
78+
hideLoading()
79+
return Promise.reject(error)
80+
}]
7881
while (chain.length > 0) {
7982
promise = promise.then(chain.shift(), chain.shift())
8083
}

lib/vuex-loading.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ function aopPromise(commit, loading, fn) {
108108
}
109109

110110
var promise = Promise.resolve(loading);
111-
var chain = [showLoading, undefined, fn.bind.apply(fn, [null].concat(arg)), undefined, hideLoading, hideLoading];
111+
var chain = [showLoading, undefined, fn.bind.apply(fn, [null].concat(arg)), undefined, hideLoading, function (error) {
112+
hideLoading();
113+
return Promise.reject(error);
114+
}];
112115
while (chain.length > 0) {
113116
promise = promise.then(chain.shift(), chain.shift());
114117
}

0 commit comments

Comments
 (0)