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
parent
7d97569027
commit
0c18a6321a
|
@ -20,7 +20,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Class = require( 'easejs' ).Class,
|
var Class = require( 'easejs' ).Class,
|
||||||
Store = require( './Store' );
|
Store = require( './Store' ),
|
||||||
|
StoreMissError = require( './StoreMissError' );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,7 +108,9 @@ module.exports = Class( 'MemoryStore' )
|
||||||
{
|
{
|
||||||
return ( this._store[ key ] !== undefined )
|
return ( this._store[ key ] !== undefined )
|
||||||
? Promise.resolve( this._store[ key ] )
|
? Promise.resolve( this._store[ key ] )
|
||||||
: Promise.reject( 'Key ' + key + ' does not exist' );
|
: Promise.reject(
|
||||||
|
StoreMissError( "Key '" + key + "' does not exist" )
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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, {} );
|
|
@ -78,7 +78,8 @@ describe( 'store.MemoryStore', () =>
|
||||||
it( 'rejects promise if store item does not exist', () =>
|
it( 'rejects promise if store item does not exist', () =>
|
||||||
{
|
{
|
||||||
return expect( Sut().get( 'unknown' ) )
|
return expect( Sut().get( 'unknown' ) )
|
||||||
.to.eventually.be.rejected;
|
.to.eventually.be.rejected
|
||||||
|
.and.be.instanceof( store.StoreMissError );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue