Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitzm@lovullo.com>2016-12-30 15:38:21 -0500
committerMike Gerwitz <gerwitzm@lovullo.com>2017-01-04 16:17:37 -0500
commit0c18a6321a617365f079d64bb56888e2d98ff145 (patch)
treef16015e371955da4b56084f1d3524ef3524db023
parent7d9756902703c9f2c2cccb6285477b4f27a800e6 (diff)
downloadliza-0c18a6321a617365f079d64bb56888e2d98ff145.tar.gz
liza-0c18a6321a617365f079d64bb56888e2d98ff145.tar.bz2
liza-0c18a6321a617365f079d64bb56888e2d98ff145.zip
Add StoreMissError
Nice and trivial with the new easejs transparent error subtyping! * src/store/StoreMissError.js: Add error class. * src/store/MemoryStore.js (get): Use it. * test/store/MemoryStoreTest.js (#get): Modify test to expect type.
-rw-r--r--src/store/MemoryStore.js9
-rw-r--r--src/store/StoreMissError.js31
-rw-r--r--test/store/MemoryStoreTest.js3
3 files changed, 39 insertions, 4 deletions
diff --git a/src/store/MemoryStore.js b/src/store/MemoryStore.js
index 52786f4..d4b92da 100644
--- a/src/store/MemoryStore.js
+++ b/src/store/MemoryStore.js
@@ -19,8 +19,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-var Class = require( 'easejs' ).Class,
- Store = require( './Store' );
+var Class = require( 'easejs' ).Class,
+ Store = require( './Store' ),
+ StoreMissError = require( './StoreMissError' );
/**
@@ -107,7 +108,9 @@ module.exports = Class( 'MemoryStore' )
{
return ( this._store[ key ] !== undefined )
? Promise.resolve( this._store[ key ] )
- : Promise.reject( 'Key ' + key + ' does not exist' );
+ : Promise.reject(
+ StoreMissError( "Key '" + key + "' does not exist" )
+ );
},
diff --git a/src/store/StoreMissError.js b/src/store/StoreMissError.js
new file mode 100644
index 0000000..8017fdb
--- /dev/null
+++ b/src/store/StoreMissError.js
@@ -0,0 +1,31 @@
+/**
+ * Error when key is not found in store
+ *
+ * Copyright (C) 2016 LoVullo Associates, Inc.
+ *
+ * This file is part of the Liza Data Collection Framework
+ *
+ * Liza is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+var Class = require( 'easejs' ).Class;
+
+
+/**
+ * Store key miss
+ *
+ * A key was not found in a store.
+ */
+module.exports = Class( 'StoreMissError' )
+ .extend( ReferenceError, {} );
diff --git a/test/store/MemoryStoreTest.js b/test/store/MemoryStoreTest.js
index 82392af..7d47bc2 100644
--- a/test/store/MemoryStoreTest.js
+++ b/test/store/MemoryStoreTest.js
@@ -78,7 +78,8 @@ describe( 'store.MemoryStore', () =>
it( 'rejects promise if store item does not exist', () =>
{
return expect( Sut().get( 'unknown' ) )
- .to.eventually.be.rejected;
+ .to.eventually.be.rejected
+ .and.be.instanceof( store.StoreMissError );
} );
} );