Skip to content

Commit 06b436b

Browse files
committed
fix: 修复http模块在处理拦截器时返回Promise实例对象导致处理错误的问题
http模块修复处理不支持Promise实例对象返回的Resolved或Rejected的值
1 parent 3dcec9f commit 06b436b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

uview-ui/libs/request/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Request {
1414
// 检查请求拦截
1515
if (this.interceptor.request && typeof this.interceptor.request === 'function') {
1616
let tmpConfig = {};
17-
let interceptorReuest = this.interceptor.request(options);
17+
let interceptorReuest = await this.interceptor.request(options);
1818
if (interceptorReuest === false) {
1919
return false;
2020
}
@@ -29,7 +29,7 @@ class Request {
2929
options.method = options.method || this.config.method;
3030

3131
return new Promise((resolve, reject) => {
32-
options.complete = (response) => {
32+
options.complete = async (response) => {
3333
// 请求返回后,隐藏loading(如果请求返回快的话,可能会没有loading)
3434
uni.hideLoading();
3535
// 清除定时器,如果请求回来了,就无需loading
@@ -38,7 +38,7 @@ class Request {
3838
if(this.config.originalData) {
3939
// 判断是否存在拦截器
4040
if (this.interceptor.response && typeof this.interceptor.response === 'function') {
41-
let resInterceptors = this.interceptor.response(response);
41+
let resInterceptors = await this.interceptor.response(response);
4242
// 如果拦截器不返回false,就将拦截器返回的内容给this.$u.post的then回调
4343
if (resInterceptors !== false) {
4444
resolve(resInterceptors);
@@ -53,7 +53,7 @@ class Request {
5353
} else {
5454
if (response.statusCode == 200) {
5555
if (this.interceptor.response && typeof this.interceptor.response === 'function') {
56-
let resInterceptors = this.interceptor.response(response.data);
56+
let resInterceptors = await this.interceptor.response(response.data);
5757
if (resInterceptors !== false) {
5858
resolve(resInterceptors);
5959
} else {

0 commit comments

Comments
 (0)