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) {
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) {
this.lastShownDate = new Date();
setTimeout(() => {
this.alertService.alert({
this.application.alertService.alert({
text: STRING_SESSION_EXPIRED
});
}, 500);

View File

@@ -74,7 +74,6 @@ class EditorCtrl extends PureCtrl {
$onInit() {
super.$onInit();
this.addSyncStatusObserver();
this.registerKeyboardShortcuts();
}
@@ -136,6 +135,11 @@ class EditorCtrl extends PureCtrl {
if (this.state.note.dirty) {
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();
}
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) {
return this.application.componentManager.editorForNote(note);
}
@@ -421,13 +410,9 @@ class EditorCtrl extends PureCtrl {
saveError: false,
syncTakingTooLong: false
});
let status = "All changes saved";
if (this.application.noAccount()) {
status += " (offline)";
}
this.setStatus(
{ message: status }
);
this.setStatus({
message: 'All changes saved',
});
}
showErrorStatus(error) {

View File

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

View File

@@ -64,12 +64,14 @@ export class WebDeviceInterface extends DeviceInterface {
async openDatabase() {
this.database.unlock();
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
this.database.openDatabase(() => {
resolve({ isNewDatabase: true });
}).then(() => {
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