feat: handle copy wiki error

This commit is contained in:
tiddlygit-test 2021-04-29 23:23:46 +08:00
parent df1c19ad1f
commit fd6cd754e1
5 changed files with 19 additions and 6 deletions

View file

@ -252,7 +252,9 @@
"InitWikiGitError": "InitWikiGitError",
"InitWikiGitErrorDescription": "The template used by the new note repository failed to copy or the git initialization of the note repository failed. This should be a bug.",
"InitWikiGitRevertError": "InitWikiGitRevertError",
"InitWikiGitRevertErrorDescription": "Not only did the initialization of the note warehouse fail, but also the revocation failed. This is a serious problem, and you need to manually clean up the new folder generated in this location."
"InitWikiGitRevertErrorDescription": "Not only did the initialization of the note warehouse fail, but also the revocation failed. This is a serious problem, and you need to manually clean up the new folder generated in this location.",
"CopyWikiTemplateError": "CopyWikiTemplateError",
"CopyWikiTemplateErrorDescription": "Attempt to copy or overwrite the latest wiki template to the corresponding location, but failed. This should be caused by a bug."
},
"Loading": "Loading",
"Yes": "Yes",

View file

@ -253,7 +253,9 @@
"InitWikiGitError": "笔记仓库初始化失败错误",
"InitWikiGitErrorDescription": "新笔记仓库所用的模板复制失败或者笔记仓库的git初始化失败这应该是个bug。",
"InitWikiGitRevertError": "笔记仓库初始化失败且撤销失败错误",
"InitWikiGitRevertErrorDescription": "不仅笔记仓库初始化失败了,而且撤销也失败了,这是个严重问题,需要你手动清理该位置生成的新文件夹。"
"InitWikiGitRevertErrorDescription": "不仅笔记仓库初始化失败了,而且撤销也失败了,这是个严重问题,需要你手动清理该位置生成的新文件夹。",
"CopyWikiTemplateError": "复制维基模板错误",
"CopyWikiTemplateErrorDescription": "尝试把最新维基模板复制或覆盖到对应位置但是失败了这应该是由bug导致的。"
},
"Loading": "加载中",
"Yes": "是的",

View file

@ -0,0 +1,9 @@
import i18n from '@services/libs/i18n';
export class CopyWikiTemplateError extends Error {
constructor(extraMessage?: string) {
super(extraMessage);
this.name = i18n.t('Error.CopyWikiTemplateError');
this.message = `${i18n.t('Error.CopyWikiTemplateErrorDescription')} ${extraMessage ?? ''}`;
}
}

View file

@ -26,6 +26,7 @@ import { TIDDLYWIKI_TEMPLATE_FOLDER_PATH, TIDDLERS_PATH } from '@/constants/path
import { updateSubWikiPluginContent, getSubWikiPluginContent, ISubWikiPluginContent } from './update-plugin-content';
import { IWikiService } from './interface';
import { WikiChannel } from '@/constants/channels';
import { CopyWikiTemplateError } from './error';
@injectable()
export class Wiki implements IWikiService {
@ -55,12 +56,11 @@ export class Wiki implements IWikiService {
}
// handlers
public async copyWikiTemplate(newFolderPath: string, folderName: string): Promise<string> {
public async copyWikiTemplate(newFolderPath: string, folderName: string): Promise<void> {
try {
await this.createWiki(newFolderPath, folderName);
return '';
} catch (error) {
return (error as Error).message;
throw new CopyWikiTemplateError((error as Error).message);
}
}

View file

@ -12,7 +12,7 @@ export interface IWikiService {
startWiki(homePath: string, tiddlyWikiPort: number, userName: string): Promise<void>;
stopWiki(homePath: string): Promise<void>;
stopAllWiki(): Promise<void>;
copyWikiTemplate(newFolderPath: string, folderName: string): Promise<string>;
copyWikiTemplate(newFolderPath: string, folderName: string): Promise<void>;
getSubWikiPluginContent(mainWikiPath: string): Promise<ISubWikiPluginContent[]>;
/** send tiddlywiki action message to current active wiki */
requestWikiSendActionMessage(actionMessage: string): Promise<void>;