How to handle network exceptions in uniapp development app

I don't think very clearly about this problem. I only think of basic solutions at the moment.

First, the client’s network is abnormal (disconnected)

1. Disconnection situation

Information prompts must pop up. The best solution currently is to write prompts in the unified method encapsulated by uni.request.

//1. 封装的网络请求
async function serviceTeng(method,url,param){
	return new Promise((resolve, reject) => {
		uni.request({ 
			url : url,
			method : method,
			data : param,
			header: {
				'authorization': uni.getStorageSync("tokenKey")
			},
			success: (res) => {
				resolve(res);
			},
			fail:(err)=>{
				reject(err);
				//客户端(App端),网路错误(请求都没发出去),弹出提示
                uni.showToast({
		            title: "网络连接失败",
		            duration: 3500,
		            icon: "error"
	            });
			}
		})
	})
}

At present, I don’t know how to handle pull-down refresh in the top tabBar. I have seen encapsulated plug-ins before, so I still need to learn about it.

Second, the server

Exceptions must be handled and results must be returned.

Guess you like

Origin blog.csdn.net/tengyuxin/article/details/132676258