Skip to content

Commit 8a026a9

Browse files
committed
优化:请求异常时增加错误码
1 parent d987650 commit 8a026a9

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- 修复:插件管理左侧溢出样式异常问题
99
- 优化:插件发布错误提醒增加错误码
1010
- 优化:打开开发者调试默认为激活状态
11+
- 优化:请求异常时增加错误码
1112

1213
## v0.2.0
1314

electron/lib/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {AppConfig} from "../../src/config";
22
import Apps from "../mapi/app";
33

44
export type ResultType<T> = {
5-
code: boolean,
5+
code: number,
66
msg: string,
7-
data: T
7+
data?: T
88
}
99

1010
export const post = async (url: string, data: any) => {

electron/mapi/user/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ const post = async <T>(api: string, data: Record<string, any>): Promise<ResultTy
157157
},
158158
body: JSON.stringify(data)
159159
})
160+
if (res.status !== 200) {
161+
return {
162+
code: -1,
163+
msg: `RequestError(code:${res.status},text:${res.statusText})`
164+
} as ResultType
165+
}
160166
const json = await res.json()
161167
// console.log('post', JSON.stringify({api, data, json}, null, 2))
162168
if (json.code) {

src/pages/System/SystemPlugin.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,15 @@ const doRefreshInstall = async () => {
143143
const doPublish = async () => {
144144
Dialog.loadingOn('正在发布')
145145
try {
146-
await window.$mapi.manager.storePublish(recordCurrent.value?.name as string, {
146+
const res = await window.$mapi.manager.storePublish(recordCurrent.value?.name as string, {
147147
version: recordCurrent.value?.version as string,
148148
})
149-
Dialog.tipSuccess('发布成功')
150-
doLoad().then()
149+
if (res.code === 0) {
150+
Dialog.alertError('发布成功')
151+
doLoad().then()
152+
} else {
153+
Dialog.alertError('发布失败:' + res.msg)
154+
}
151155
} catch (e) {
152156
Dialog.tipError('发布失败:' + mapError(e))
153157
} finally {
@@ -225,7 +229,9 @@ const doInstallStore = async () => {
225229
<div class="flex-grow w-0 truncate">
226230
<div class="text-lg leading-6 flex items-center">
227231
<div class="font-bold mr-2">{{ recordCurrent.title }}</div>
228-
<div class="text-gray-400" v-if="recordCurrent.type!==PluginType.SYSTEM">v{{ recordCurrent.version }}</div>
232+
<div class="text-gray-400" v-if="recordCurrent.type!==PluginType.SYSTEM">
233+
v{{ recordCurrent.version }}
234+
</div>
229235
<a-tooltip :content="'本地插件:'+recordCurrent.runtime?.root">
230236
<a-tag v-if="recordCurrent.type==='dir'" size="small" color="red" class="ml-2 text-xs">
231237
DEV

0 commit comments

Comments
 (0)