Handle errors on loading settings

The error on loading settings can occurs when the settings lose backward
compatibility on version up, or the saved date is broken.  The error is
caught, then the script done fallback to default settings and notify it
to user.
This commit is contained in:
Shin'ya Ueoka 2019-07-30 21:52:22 +09:00
parent 3db11041c5
commit 33a16b85e4
4 changed files with 26 additions and 6 deletions

View file

@ -4,6 +4,7 @@ import PersistentSettingRepository
import SettingRepository from '../repositories/SettingRepository';
import { DefaultSettingData } from '../../shared/SettingData';
import Settings from '../../shared/Settings';
import NotifyPresenter from '../presenters/NotifyPresenter';
@injectable()
export default class SettingUseCase {
@ -11,6 +12,7 @@ export default class SettingUseCase {
constructor(
private persistentSettingRepository: PersistentSettingRepository,
private settingRepository: SettingRepository,
private notifyPresenter: NotifyPresenter,
) {
}
@ -24,8 +26,14 @@ export default class SettingUseCase {
data = DefaultSettingData;
}
let value = data.toSettings();
this.settingRepository.update(value);
let value: Settings;
try {
value = data.toSettings();
} catch (e) {
this.notifyPresenter.notifyInvalidSettings(() => {});
value = DefaultSettingData.toSettings();
}
this.settingRepository.update(value!!);
return value;
}
}