Skip to content

Commit 0039aa7

Browse files
committed
Better error handling.
1 parent 0f6d9a6 commit 0039aa7

4 files changed

Lines changed: 453 additions & 396 deletions

File tree

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
"name": "lambda-badger",
33
"version": "0.1.0",
44
"private": true,
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/Jimskapt/lambda-badger.git"
8+
},
9+
"contributors": [
10+
"Jimskapt <rami.programmer@gmail.com>"
11+
],
512
"scripts": {
613
"serve": "vue-cli-service serve",
714
"build": "vue-cli-service build",

src/store.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const store = new Vuex.Store({
6666
state.settings.locale = payload.value;
6767
i18n.locale = payload.value;
6868

69+
const that = this;
6970
dbSettings.get('locale')
7071
.then((doc) => {
7172
doc.value = payload.value;
@@ -78,7 +79,7 @@ const store = new Vuex.Store({
7879
value: payload.value,
7980
});
8081
} else {
81-
// TODO
82+
that.$toasted.show(err, { duration: 4000, type: 'error', icon: 'warning' });
8283
}
8384
});
8485

@@ -93,6 +94,7 @@ const store = new Vuex.Store({
9394
}
9495
state.settings.darkMode = payload.value;
9596

97+
const that = this;
9698
dbSettings.get('dark_mode')
9799
.then((doc) => {
98100
doc.value = payload.value;
@@ -105,7 +107,7 @@ const store = new Vuex.Store({
105107
value: payload.value,
106108
});
107109
} else {
108-
// TODO
110+
that.$toasted.show(err, { duration: 4000, type: 'error', icon: 'warning' });
109111
}
110112
});
111113

@@ -121,6 +123,7 @@ const store = new Vuex.Store({
121123
payload.value = payload.value.trim();
122124
state.settings.couchUrl = payload.value;
123125

126+
const that = this;
124127
dbSettings.get('couch_url')
125128
.then((doc) => {
126129
doc.value = payload.value;
@@ -133,7 +136,7 @@ const store = new Vuex.Store({
133136
value: payload.value,
134137
});
135138
} else {
136-
// TODO
139+
that.$toasted.show(err, { duration: 4000, type: 'error', icon: 'warning' });
137140
}
138141
});
139142
} else {
@@ -147,6 +150,7 @@ const store = new Vuex.Store({
147150
}
148151
state.settings.allowAutomaticUpdate = payload.value;
149152

153+
const that = this;
150154
dbSettings.get('allow_automatic_update')
151155
.then((doc) => {
152156
doc.value = payload.value;
@@ -159,7 +163,7 @@ const store = new Vuex.Store({
159163
value: payload.value,
160164
});
161165
} else {
162-
// TODO
166+
that.$toasted.show(err, { duration: 4000, type: 'error', icon: 'warning' });
163167
}
164168
});
165169
} else {
@@ -226,7 +230,7 @@ const store = new Vuex.Store({
226230
reject(err);
227231
});
228232
} else {
229-
reject({message: 'not ok'}); // TODO
233+
reject({message: 'error while saving document'});
230234
}
231235
};
232236

@@ -284,6 +288,7 @@ const store = new Vuex.Store({
284288
};
285289
}
286290

291+
const that = this;
287292
new Promise((resolve) => {
288293
if(dbSync !== null && store.state.settings.couchUrl !== store.state.settings.currentSync) {
289294
context.dispatch('stopSyncDB').then(() => { resolve(); });
@@ -306,10 +311,14 @@ const store = new Vuex.Store({
306311
}, 2000);
307312
}
308313
})
309-
.on('error', (err) => { alert('CPE0006: Error while synchronising database : ' + err); }); // TODO
314+
.on('error', (err) => {
315+
that.$toasted.show(err, { duration: 4000, type: 'error', icon: 'warning' });
316+
});
310317
}
311318
})
312-
.catch((err) => { alert('CPE0007: ' + err); });
319+
.catch((err) => {
320+
that.$toasted.show(err, { duration: 4000, type: 'error', icon: 'warning' });
321+
});
313322
},
314323
stopSyncDB() {
315324
return new Promise((resolve) => {
@@ -414,7 +423,7 @@ db.changes({
414423
}
415424
})
416425
.on('error', (err) => {
417-
console.log('zrfrfgazrgerg', err);
426+
console.log(err);
418427
});
419428

420429
export default store;

src/views/EditNote.vue

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,31 @@ export default {
6767
.then((res) => {
6868
if(res.ok) {
6969
if(typeof(res.doc) !== 'undefined') {
70-
that.$set(this, 'dbDoc', res.doc);
70+
that.$set(that, 'dbDoc', res.doc);
7171
} else {
72-
console.error('CPE0003', res);
72+
that.$toasted.show('Error while fetching saving note', { duration: 4000, type: 'error', icon: 'warning' });
7373
}
7474
} else {
75-
console.error('CPE0001:', res);
76-
// TODO
75+
that.$toasted.show('Error while saving note', { duration: 4000, type: 'error', icon: 'warning' });
7776
}
7877
})
79-
.catch((err) => { console.error('CPE0002:', err); }); // TODO
78+
.catch((err) => {
79+
that.$toasted.show(err, { duration: 4000, type: 'error', icon: 'warning' });
80+
});
8081
},
8182
deleteNote() {
83+
const that = this;
8284
this.$store.dispatch('deleteNote', {data: this.dbDoc})
8385
.then((res) => {
8486
if(res.ok) {
85-
this.$router.push({ name: 'notes' });
87+
that.$router.push({ name: 'notes' });
8688
} else {
87-
console.error('CPE0009:', res);
88-
// TODO
89+
that.$toasted.show('Error while deleting document', { duration: 4000, type: 'error', icon: 'warning' });
8990
}
9091
})
91-
.catch((err) => { console.error('CPE0010:', err); }); // TODO
92+
.catch((err) => {
93+
that.$toasted.show(err, { duration: 4000, type: 'error', icon: 'warning' });
94+
});
9295
}
9396
},
9497
created() {

0 commit comments

Comments
 (0)