1
0
Fork 0

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.
master
Mike Gerwitz 2016-12-30 15:38:21 -05:00
parent 7d97569027
commit 0c18a6321a
3 changed files with 39 additions and 4 deletions

View File

@ -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" )
);
},

View File

@ -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, {} );

View File

@ -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 );
} );
} );