Database exception handling

This commit is contained in:
Mo Bitar
2020-03-25 22:04:14 -05:00
parent a80a94de5e
commit 9d6c32890a
6 changed files with 96 additions and 98 deletions

View File

@@ -112,6 +112,14 @@ class ApplicationViewCtrl extends PureCtrl {
} }
} else if (eventName === ApplicationEvents.InvalidSyncSession) { } else if (eventName === ApplicationEvents.InvalidSyncSession) {
this.showInvalidSessionAlert(); this.showInvalidSessionAlert();
} else if(eventName === ApplicationEvents.LocalDatabaseReadError) {
this.application.alertService.alert({
text: 'Unable to load local database. Please restart the app and try again.'
});
} else if (eventName === ApplicationEvents.LocalDatabaseWriteError) {
this.application.alertService.alert({
text: 'Unable to write to local database. Please restart the app and try again.'
});
} }
} }
@@ -218,7 +226,7 @@ class ApplicationViewCtrl extends PureCtrl {
if (!this.lastShownDate || lastShownSeconds > SHOW_INTERVAL) { if (!this.lastShownDate || lastShownSeconds > SHOW_INTERVAL) {
this.lastShownDate = new Date(); this.lastShownDate = new Date();
setTimeout(() => { setTimeout(() => {
this.alertService.alert({ this.application.alertService.alert({
text: STRING_SESSION_EXPIRED text: STRING_SESSION_EXPIRED
}); });
}, 500); }, 500);

View File

@@ -74,7 +74,6 @@ class EditorCtrl extends PureCtrl {
$onInit() { $onInit() {
super.$onInit(); super.$onInit();
this.addSyncStatusObserver();
this.registerKeyboardShortcuts(); this.registerKeyboardShortcuts();
} }
@@ -136,6 +135,11 @@ class EditorCtrl extends PureCtrl {
if (this.state.note.dirty) { if (this.state.note.dirty) {
this.showErrorStatus(); this.showErrorStatus();
} }
} else if (eventName === ApplicationEvents.LocalDatabaseWriteError) {
this.showErrorStatus({
message: "Offline Saving Issue",
desc: "Changes not saved"
});
} }
} }
@@ -256,21 +260,6 @@ class EditorCtrl extends PureCtrl {
this.reloadComponentContext(); this.reloadComponentContext();
} }
addSyncStatusObserver() {
/** @todo */
// this.syncStatusObserver = syncManager.
// registerSyncStatusObserver((status) => {
// if (status.localError) {
// this.$timeout(() => {
// this.showErrorStatus({
// message: "Offline Saving Issue",
// desc: "Changes not saved"
// });
// }, 500);
// }
// });
}
editorForNote(note) { editorForNote(note) {
return this.application.componentManager.editorForNote(note); return this.application.componentManager.editorForNote(note);
} }
@@ -421,13 +410,9 @@ class EditorCtrl extends PureCtrl {
saveError: false, saveError: false,
syncTakingTooLong: false syncTakingTooLong: false
}); });
let status = "All changes saved"; this.setStatus({
if (this.application.noAccount()) { message: 'All changes saved',
status += " (offline)"; });
}
this.setStatus(
{ message: status }
);
} }
showErrorStatus(error) { showErrorStatus(error) {

View File

@@ -104,7 +104,7 @@ export class Database {
/** @access public */ /** @access public */
async getAllPayloads() { async getAllPayloads() {
const db = await this.openDatabase(); const db = await this.openDatabase();
return new Promise((resolve) => { return new Promise((resolve, reject) => {
const objectStore = const objectStore =
db.transaction(STORE_NAME). db.transaction(STORE_NAME).
objectStore(STORE_NAME); objectStore(STORE_NAME);
@@ -170,11 +170,11 @@ export class Database {
/** @access public */ /** @access public */
async deletePayload(uuid) { async deletePayload(uuid) {
const db = await this.openDatabase(); const db = await this.openDatabase();
const request =
db.transaction(STORE_NAME, READ_WRITE)
.objectStore(STORE_NAME)
.delete(uuid);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const request =
db.transaction(STORE_NAME, READ_WRITE)
.objectStore(STORE_NAME)
.delete(uuid);
request.onsuccess = resolve; request.onsuccess = resolve;
request.onerror = reject; request.onerror = reject;
}); });

View File

@@ -64,12 +64,14 @@ export class WebDeviceInterface extends DeviceInterface {
async openDatabase() { async openDatabase() {
this.database.unlock(); this.database.unlock();
return new Promise((resolve) => { return new Promise((resolve, reject) => {
this.database.openDatabase(() => { this.database.openDatabase(() => {
resolve({ isNewDatabase: true }); resolve({ isNewDatabase: true });
}).then(() => { }).then(() => {
resolve({ isNewDatabase: false }); resolve({ isNewDatabase: false });
}); }).catch((error => {
reject(error);
}));
}); });
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long