|
@@ -1,4 +1,4 @@
|
|
|
-import util from './util.js'
|
|
|
+import util, { isFunc } from './util.js'
|
|
|
class request {
|
|
|
|
|
|
//本地的
|
|
@@ -37,9 +37,9 @@ class request {
|
|
|
/**
|
|
|
* POST类型的网络请求
|
|
|
*/
|
|
|
- static postRequest(url, data, notUseLoading) {
|
|
|
+ static postRequest(url, data, notUseLoading, catchErrorFunc) {
|
|
|
let headerSign = this.getSignHead();
|
|
|
- return this.requestAll(url, data, headerSign, 'POST', notUseLoading)
|
|
|
+ return this.requestAll(url, data, headerSign, 'POST', notUseLoading, catchErrorFunc)
|
|
|
}
|
|
|
|
|
|
static upload(url, name, path, ortherData, header = this.HEAD){
|
|
@@ -98,7 +98,7 @@ class request {
|
|
|
/**
|
|
|
* 网络请求
|
|
|
*/
|
|
|
- static requestAll(url, data, header, method, notUseLoading) {
|
|
|
+ static requestAll(url, data, header, method, notUseLoading, catchErrorFunc) {
|
|
|
if (!notUseLoading) {
|
|
|
getApp().showLoading()
|
|
|
}
|
|
@@ -113,16 +113,22 @@ class request {
|
|
|
//200: 服务端业务处理正常结束
|
|
|
resolve(res?.data)
|
|
|
} else {
|
|
|
- wx.showToast({
|
|
|
- title: res?.data?.msg,
|
|
|
- icon: "none"
|
|
|
- })
|
|
|
- //其它错误,提示用户错误信息
|
|
|
- if (this._errorHandler != null) {
|
|
|
- //如果有统一的异常处理,就先调用统一异常处理函数对异常进行处理
|
|
|
- this._errorHandler(res)
|
|
|
- }
|
|
|
- reject(res)
|
|
|
+ if (catchErrorFunc) {
|
|
|
+ if (isFunc(catchErrorFunc)) {
|
|
|
+ catchErrorFunc(res?.data)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: res?.data?.msg,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ }
|
|
|
+ //其它错误,提示用户错误信息
|
|
|
+ if (this._errorHandler != null) {
|
|
|
+ //如果有统一的异常处理,就先调用统一异常处理函数对异常进行处理
|
|
|
+ this._errorHandler(res)
|
|
|
+ }
|
|
|
+ reject(res)
|
|
|
}
|
|
|
}),
|
|
|
fail: (res => {
|