Skip to content

Commit

Permalink
Better error handlin
Browse files Browse the repository at this point in the history
Added error handling of .value() after multiple .get() chained on non-existant values.

Credit to @LucAngevare for his contributions.
  • Loading branch information
Tom committed Jan 21, 2021
1 parent 85c96a9 commit c19feba
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/stormdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class StormDB {
value() {
let data = this.state;
for (let i = 0; i < this.pointers.length; i++) {
if (i < this.pointers.length - 1 && !data[this.pointers[i]]) {
throw new Error("Can't run .value() on non-existant data.");
}
data = data[this.pointers[i]];
}

Expand Down

0 comments on commit c19feba

Please sign in to comment.