Commit 06b436b5 authored by 费陶勇's avatar 费陶勇

fix: 修复http模块在处理拦截器时返回Promise实例对象导致处理错误的问题

http模块修复处理不支持Promise实例对象返回的Resolved或Rejected的值
parent 3dcec9f3
...@@ -14,7 +14,7 @@ class Request { ...@@ -14,7 +14,7 @@ class Request {
// 检查请求拦截 // 检查请求拦截
if (this.interceptor.request && typeof this.interceptor.request === 'function') { if (this.interceptor.request && typeof this.interceptor.request === 'function') {
let tmpConfig = {}; let tmpConfig = {};
let interceptorReuest = this.interceptor.request(options); let interceptorReuest = await this.interceptor.request(options);
if (interceptorReuest === false) { if (interceptorReuest === false) {
return false; return false;
} }
...@@ -29,7 +29,7 @@ class Request { ...@@ -29,7 +29,7 @@ class Request {
options.method = options.method || this.config.method; options.method = options.method || this.config.method;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
options.complete = (response) => { options.complete = async (response) => {
// 请求返回后,隐藏loading(如果请求返回快的话,可能会没有loading) // 请求返回后,隐藏loading(如果请求返回快的话,可能会没有loading)
uni.hideLoading(); uni.hideLoading();
// 清除定时器,如果请求回来了,就无需loading // 清除定时器,如果请求回来了,就无需loading
...@@ -38,7 +38,7 @@ class Request { ...@@ -38,7 +38,7 @@ class Request {
if(this.config.originalData) { if(this.config.originalData) {
// 判断是否存在拦截器 // 判断是否存在拦截器
if (this.interceptor.response && typeof this.interceptor.response === 'function') { if (this.interceptor.response && typeof this.interceptor.response === 'function') {
let resInterceptors = this.interceptor.response(response); let resInterceptors = await this.interceptor.response(response);
// 如果拦截器不返回false,就将拦截器返回的内容给this.$u.post的then回调 // 如果拦截器不返回false,就将拦截器返回的内容给this.$u.post的then回调
if (resInterceptors !== false) { if (resInterceptors !== false) {
resolve(resInterceptors); resolve(resInterceptors);
...@@ -53,7 +53,7 @@ class Request { ...@@ -53,7 +53,7 @@ class Request {
} else { } else {
if (response.statusCode == 200) { if (response.statusCode == 200) {
if (this.interceptor.response && typeof this.interceptor.response === 'function') { if (this.interceptor.response && typeof this.interceptor.response === 'function') {
let resInterceptors = this.interceptor.response(response.data); let resInterceptors = await this.interceptor.response(response.data);
if (resInterceptors !== false) { if (resInterceptors !== false) {
resolve(resInterceptors); resolve(resInterceptors);
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment