Skip to content

Commit

Permalink
优化:请求异常时增加错误码
Browse files Browse the repository at this point in the history
  • Loading branch information
modstart committed Dec 27, 2024
1 parent d987650 commit 8a026a9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- 修复:插件管理左侧溢出样式异常问题
- 优化:插件发布错误提醒增加错误码
- 优化:打开开发者调试默认为激活状态
- 优化:请求异常时增加错误码

## v0.2.0

Expand Down
4 changes: 2 additions & 2 deletions electron/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {AppConfig} from "../../src/config";
import Apps from "../mapi/app";

export type ResultType<T> = {
code: boolean,
code: number,
msg: string,
data: T
data?: T
}

export const post = async (url: string, data: any) => {
Expand Down
6 changes: 6 additions & 0 deletions electron/mapi/user/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ const post = async <T>(api: string, data: Record<string, any>): Promise<ResultTy
},
body: JSON.stringify(data)
})
if (res.status !== 200) {
return {
code: -1,
msg: `RequestError(code:${res.status},text:${res.statusText})`
} as ResultType
}
const json = await res.json()
// console.log('post', JSON.stringify({api, data, json}, null, 2))
if (json.code) {
Expand Down
14 changes: 10 additions & 4 deletions src/pages/System/SystemPlugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,15 @@ const doRefreshInstall = async () => {
const doPublish = async () => {
Dialog.loadingOn('正在发布')
try {
await window.$mapi.manager.storePublish(recordCurrent.value?.name as string, {
const res = await window.$mapi.manager.storePublish(recordCurrent.value?.name as string, {
version: recordCurrent.value?.version as string,
})
Dialog.tipSuccess('发布成功')
doLoad().then()
if (res.code === 0) {
Dialog.alertError('发布成功')
doLoad().then()
} else {
Dialog.alertError('发布失败:' + res.msg)
}
} catch (e) {
Dialog.tipError('发布失败:' + mapError(e))
} finally {
Expand Down Expand Up @@ -225,7 +229,9 @@ const doInstallStore = async () => {
<div class="flex-grow w-0 truncate">
<div class="text-lg leading-6 flex items-center">
<div class="font-bold mr-2">{{ recordCurrent.title }}</div>
<div class="text-gray-400" v-if="recordCurrent.type!==PluginType.SYSTEM">v{{ recordCurrent.version }}</div>
<div class="text-gray-400" v-if="recordCurrent.type!==PluginType.SYSTEM">
v{{ recordCurrent.version }}
</div>
<a-tooltip :content="'本地插件:'+recordCurrent.runtime?.root">
<a-tag v-if="recordCurrent.type==='dir'" size="small" color="red" class="ml-2 text-xs">
DEV
Expand Down

0 comments on commit 8a026a9

Please sign in to comment.