Unify success codes and update upload deps
This commit is contained in:
@@ -431,7 +431,7 @@ export const postComment = async (commentData: PostCommentRequest): Promise<Post
|
||||
|
||||
const json = await response.json();
|
||||
handlePostApiCode(json);
|
||||
if (json.code === 1001 && json.data?.id !== undefined) {
|
||||
if (json.code === 1000 && json.data?.id !== undefined) {
|
||||
return { id: Number(json.data.id) };
|
||||
}
|
||||
if (json.code === 2005) {
|
||||
@@ -466,7 +466,7 @@ export const reportPost = async (reportData: { id: number; title: string; conten
|
||||
}
|
||||
const json = await response.json();
|
||||
handlePostApiCode(json);
|
||||
if (json.code === 1001 && json.data?.id !== undefined) {
|
||||
if (json.code === 1000 && json.data?.id !== undefined) {
|
||||
return { id: Number(json.data.id) };
|
||||
}
|
||||
throw new Error(json.data || 'Report failed');
|
||||
@@ -493,12 +493,15 @@ export const uploadImage = async (file: File): Promise<string> => {
|
||||
}
|
||||
const json = await response.json();
|
||||
handlePostApiCode(json);
|
||||
if (json.code === 1001 && typeof json.data === 'string') {
|
||||
if (json.code === 1000 && typeof json.data === 'string') {
|
||||
return json.data;
|
||||
}
|
||||
if (json.code === 2006) {
|
||||
throw new Error('UPLOAD_TOO_LARGE');
|
||||
}
|
||||
if (json.code === 2008) {
|
||||
throw new Error('CORRUPTED_IMAGE');
|
||||
}
|
||||
if (json.code === 2007) {
|
||||
throw new Error('UNSUPPORTED_FORMAT');
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ const CreatePost: React.FC = () => {
|
||||
|
||||
try {
|
||||
const response = await createPost(value);
|
||||
if (response.code === 1001 || response.code === 1002) {
|
||||
if (response.code === 1000 || response.code === 1002) {
|
||||
// 清除草稿
|
||||
saveDraft('');
|
||||
setValue('');
|
||||
@@ -318,6 +318,13 @@ const CreatePost: React.FC = () => {
|
||||
</Toast>,
|
||||
{ intent: 'error' }
|
||||
);
|
||||
} else if (msg.includes('CORRUPTED_IMAGE')) {
|
||||
dispatchToast(
|
||||
<Toast>
|
||||
<ToastTitle>上传的文件损坏</ToastTitle>
|
||||
</Toast>,
|
||||
{ intent: 'error' }
|
||||
);
|
||||
} else if (msg.includes('UNSUPPORTED_FORMAT')) {
|
||||
dispatchToast(
|
||||
<Toast>
|
||||
|
||||
Reference in New Issue
Block a user