Skip to content

Commit

Permalink
perf: improve the prompt for upload failure of the upload component (h…
Browse files Browse the repository at this point in the history
…alo-dev/console#769)

#### What type of PR is this?

/kind improvement

#### What this PR does / why we need it:

优化上传组件的异常提示信息。

#### Which issue(s) this PR fixes:

Fixes halo-dev#2933
Ref halo-dev#2932 halo-dev#2931

#### Screenshots:

<img width="794" alt="image" src="https://user-images.githubusercontent.com/21301288/207272593-b94efb0a-7033-4ec1-b1eb-f2e3871b34f0.png">
<img width="674" alt="image" src="https://user-images.githubusercontent.com/21301288/207272682-0c223d29-8c4f-45b0-a8d5-2432a97835c6.png">


#### Special notes for your reviewer:

测试方式:

1. 进入附件上传、插件安装、主题安装界面。
2. 上传不符合规则的文件,比如主题可以上传一个不是主题的 zip 或者 Halo 1.x 版本的 zip。
3. 观察是否有异常提示。

#### Does this PR introduce a user-facing change?

```release-note
优化 Console 端上传组件的异常提示信息。
```
  • Loading branch information
ruibaby authored Dec 14, 2022
1 parent 9e1f054 commit 97d2066
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/components/upload/UppyUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type { Restrictions } from "@uppy/core";
import XHRUpload from "@uppy/xhr-upload";
import zh_CN from "@uppy/locales/lib/zh_CN";
import { computed, onUnmounted } from "vue";
import { Toast } from "@halo-dev/components";
import type { ProblemDetail } from "@/utils/api-client";
const props = withDefaults(
defineProps<{
Expand Down Expand Up @@ -50,6 +52,18 @@ const uppy = computed(() => {
fieldName: props.name,
method: props.method,
limit: 5,
getResponseError: (responseText) => {
const response = JSON.parse(responseText);
const { title, detail } = (response || {}) as ProblemDetail;
const message = [title, detail].filter(Boolean).join(": ");
if (message) {
Toast.error(message, { duration: 5000 });
return new Error(message);
}
return new Error("Internal Server Error");
},
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const axiosInstance = axios.create({
withCredentials: true,
});

interface ProblemDetail {
export interface ProblemDetail {
detail: string;
instance: string;
status: number;
Expand Down

0 comments on commit 97d2066

Please sign in to comment.