mirror of
https://github.com/usememos/memos.git
synced 2024-12-21 02:01:55 +03:00
chore: update error message handler
This commit is contained in:
parent
a98e64cf0a
commit
f06a3d171b
@ -30,7 +30,8 @@ const ArchivedMemo: React.FC<Props> = (props: Props) => {
|
||||
await memoService.deleteMemoById(memo.id);
|
||||
await memoService.fetchAllMemos();
|
||||
} catch (error: any) {
|
||||
toastHelper.error(error.message);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
} else {
|
||||
toggleConfirmDeleteBtn();
|
||||
@ -46,7 +47,8 @@ const ArchivedMemo: React.FC<Props> = (props: Props) => {
|
||||
await memoService.fetchAllMemos();
|
||||
toastHelper.info("Restored successfully");
|
||||
} catch (error: any) {
|
||||
toastHelper.error(error.message);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -23,7 +23,8 @@ const ArchivedMemoDialog: React.FC<Props> = (props: Props) => {
|
||||
setArchivedMemos(result);
|
||||
})
|
||||
.catch((error) => {
|
||||
toastHelper.error("Failed to fetch archived memos: ", error);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
})
|
||||
.finally(() => {
|
||||
loadingState.setFinish();
|
||||
|
@ -66,7 +66,8 @@ const ChangePasswordDialog: React.FC<Props> = ({ destroy }: Props) => {
|
||||
toastHelper.info("Password changed.");
|
||||
handleCloseBtnClick();
|
||||
} catch (error: any) {
|
||||
toastHelper.error(error);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -61,7 +61,8 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
||||
});
|
||||
}
|
||||
} catch (error: any) {
|
||||
toastHelper.error(error.message);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
destroy();
|
||||
};
|
||||
|
@ -103,7 +103,8 @@ const Memo: React.FC<Props> = (props: Props) => {
|
||||
rowStatus: "ARCHIVED",
|
||||
});
|
||||
} catch (error: any) {
|
||||
toastHelper.error(error.message);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
|
||||
if (editorStateService.getState().editMemoId === memo.id) {
|
||||
@ -125,7 +126,7 @@ const Memo: React.FC<Props> = (props: Props) => {
|
||||
if (memoTemp) {
|
||||
showMemoCardDialog(memoTemp);
|
||||
} else {
|
||||
toastHelper.error("MEMO Not Found");
|
||||
toastHelper.error("Memo Not Found");
|
||||
targetEl.classList.remove("memo-link-text");
|
||||
}
|
||||
} else if (targetEl.className === "tag-span") {
|
||||
|
@ -87,7 +87,7 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
|
||||
setLinkedMemos([]);
|
||||
setMemo(nextMemo);
|
||||
} else {
|
||||
toastHelper.error("MEMO Not Found");
|
||||
toastHelper.error("Memo Not Found");
|
||||
targetEl.classList.remove("memo-link-text");
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,8 @@ const MemoEditor: React.FC<Props> = () => {
|
||||
const url = `/h/r/${image.id}/${image.filename}`;
|
||||
return url;
|
||||
} catch (error: any) {
|
||||
toastHelper.error("Failed to upload image\n" + JSON.stringify(error, null, 4));
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
} finally {
|
||||
setState({
|
||||
...state,
|
||||
@ -155,7 +156,8 @@ const MemoEditor: React.FC<Props> = () => {
|
||||
locationService.clearQuery();
|
||||
}
|
||||
} catch (error: any) {
|
||||
toastHelper.error(error.message);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
|
||||
setState({
|
||||
|
@ -84,8 +84,9 @@ const MemoList: React.FC<Props> = () => {
|
||||
.then(() => {
|
||||
setFetchStatus(false);
|
||||
})
|
||||
.catch(() => {
|
||||
toastHelper.error("😭 Fetching failed, please try again later.");
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
});
|
||||
}, []);
|
||||
|
||||
|
@ -42,7 +42,8 @@ const MenuBtnsPopup: React.FC<Props> = (props: Props) => {
|
||||
toastHelper.info(JSON.stringify(profile, null, 4));
|
||||
})
|
||||
.catch((error) => {
|
||||
toastHelper.error("Failed to ping\n" + JSON.stringify(error, null, 4));
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,8 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
|
||||
useEffect(() => {
|
||||
fetchResources()
|
||||
.catch((error) => {
|
||||
toastHelper.error("Failed to fetch archived memos: ", error);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
})
|
||||
.finally(() => {
|
||||
loadingState.setFinish();
|
||||
@ -67,7 +68,8 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
|
||||
try {
|
||||
await resourceService.upload(file);
|
||||
} catch (error: any) {
|
||||
toastHelper.error("Failed to upload resource\n" + JSON.stringify(error, null, 4));
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
} finally {
|
||||
setState({
|
||||
...state,
|
||||
|
@ -64,7 +64,8 @@ const PreferencesSection: React.FC<Props> = () => {
|
||||
try {
|
||||
await api.createUser(userCreate);
|
||||
} catch (error: any) {
|
||||
toastHelper.error(error.message);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
await fetchUserList();
|
||||
setState({
|
||||
|
@ -46,7 +46,8 @@ const MyAccountSection: React.FC<Props> = () => {
|
||||
});
|
||||
toastHelper.info("Username changed");
|
||||
} catch (error: any) {
|
||||
toastHelper.error(error.message);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -56,10 +56,10 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
|
||||
destroy();
|
||||
};
|
||||
|
||||
const handleImageOnLoad = (ev: React.SyntheticEvent<HTMLImageElement>) => {
|
||||
if (ev.type === "error") {
|
||||
toastHelper.error("😟 Image load failed");
|
||||
(ev.target as HTMLImageElement).remove();
|
||||
const handleImageOnLoad = (event: React.SyntheticEvent<HTMLImageElement>) => {
|
||||
if (event.type === "error") {
|
||||
toastHelper.error("Image load failed");
|
||||
(event.target as HTMLImageElement).remove();
|
||||
}
|
||||
setImgAmount(imgAmount - 1);
|
||||
};
|
||||
|
@ -78,7 +78,8 @@ const ShortcutContainer: React.FC<ShortcutContainerProps> = (props: ShortcutCont
|
||||
try {
|
||||
await shortcutService.deleteShortcutById(shortcut.id);
|
||||
} catch (error: any) {
|
||||
toastHelper.error(error.message);
|
||||
console.error(error);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
} else {
|
||||
toggleConfirmDeleteBtn();
|
||||
|
@ -11,7 +11,7 @@ import "../less/auth.less";
|
||||
interface Props {}
|
||||
|
||||
const validateConfig: ValidatorConfig = {
|
||||
minLength: 6,
|
||||
minLength: 4,
|
||||
maxLength: 24,
|
||||
noSpace: true,
|
||||
noChinese: true,
|
||||
@ -71,11 +71,11 @@ const Auth: React.FC<Props> = () => {
|
||||
if (user) {
|
||||
locationService.replaceHistory("/");
|
||||
} else {
|
||||
toastHelper.error("😟 Login failed");
|
||||
toastHelper.error("Login failed");
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
toastHelper.error("😟 " + error.message);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
actionBtnLoadingState.setFinish();
|
||||
};
|
||||
@ -104,11 +104,11 @@ const Auth: React.FC<Props> = () => {
|
||||
if (user) {
|
||||
locationService.replaceHistory("/");
|
||||
} else {
|
||||
toastHelper.error("😟 Signup failed");
|
||||
toastHelper.error("Signup failed");
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
toastHelper.error("😟 " + error.message);
|
||||
toastHelper.error(error.response.data.message);
|
||||
}
|
||||
actionBtnLoadingState.setFinish();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user