From 04c077d614b3eae95da1e9b506171a87948a4179 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 27 Aug 2019 22:33:33 +0900 Subject: Fix undefined checking on operation parameter --- src/background/usecases/SettingUseCase.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/background') diff --git a/src/background/usecases/SettingUseCase.ts b/src/background/usecases/SettingUseCase.ts index ee131c7..d73521f 100644 --- a/src/background/usecases/SettingUseCase.ts +++ b/src/background/usecases/SettingUseCase.ts @@ -21,7 +21,12 @@ export default class SettingUseCase { } async reload(): Promise { - let data = await this.persistentSettingRepository.load(); + let data; + try { + data = await this.persistentSettingRepository.load(); + } catch (e) { + this.showUnableToLoad(e); + } if (!data) { data = DefaultSettingData; } @@ -30,12 +35,17 @@ export default class SettingUseCase { try { value = data.toSettings(); } catch (e) { - this.notifyPresenter.notifyInvalidSettings(() => { - browser.runtime.openOptionsPage(); - }); + this.showUnableToLoad(e); value = DefaultSettingData.toSettings(); } this.settingRepository.update(value!!); return value; } + + private showUnableToLoad(e: Error) { + console.error('unable to load settings', e); + this.notifyPresenter.notifyInvalidSettings(() => { + browser.runtime.openOptionsPage(); + }); + } } -- cgit v1.2.3