用户 / 订单 / 商品 管理
This commit is contained in:
@@ -24,12 +24,18 @@ const request = (() => {
|
||||
return Promise.reject('未登录');
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
// 解析响应体
|
||||
let result;
|
||||
try { result = await response.json(); } catch (e) {
|
||||
const msg = 'HTTP ' + response.status + ' 请求失败';
|
||||
ElementPlus ? ElementPlus.ElMessage.error(msg) : alert(msg);
|
||||
return Promise.reject(msg);
|
||||
}
|
||||
|
||||
// 业务异常
|
||||
if (result.status !== 200) {
|
||||
const msg = result.message || '请求失败';
|
||||
alert(msg);
|
||||
// 业务异常:code 不为 "0" 表示失败
|
||||
if (result.code !== '0') {
|
||||
const msg = result.msg || '请求失败';
|
||||
ElementPlus ? ElementPlus.ElMessage.error(msg) : alert(msg);
|
||||
return Promise.reject(msg);
|
||||
}
|
||||
|
||||
@@ -42,7 +48,7 @@ const request = (() => {
|
||||
return http(url + query, { method: 'GET' });
|
||||
},
|
||||
post(url, data) {
|
||||
return http(url, { method: 'POST', body: JSON.stringify(data) });
|
||||
return http(url, { method: 'POST', body: data != null ? JSON.stringify(data) : undefined });
|
||||
},
|
||||
put(url, data) {
|
||||
return http(url, { method: 'PUT', body: JSON.stringify(data) });
|
||||
|
||||
Reference in New Issue
Block a user