File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,13 @@ export default class Microlock extends EventEmitter {
133133 return resolve ( val )
134134 } ) ;
135135 } )
136- . catch ( ( ) => this . __throwAlreadyLocked ( ) ) ;
136+ . catch ( ( e ) => {
137+ // Key already exists
138+ if ( e . errorCode === 105 ) {
139+ this . __throwAlreadyLocked ( ) ;
140+ }
141+ throw e ;
142+ } ) ;
137143 }
138144
139145 unlock ( ) {
@@ -143,12 +149,18 @@ export default class Microlock extends EventEmitter {
143149 return resolve ( res ) ;
144150 } ) ;
145151 } )
146- . catch ( ( ) => this . __throwLockNotOwned ( ) ) ;
152+ . catch ( ( e ) => {
153+ // KeyNotFound or CompareFailed
154+ if ( e . errorCode === 100 || e . errorCode === 101 ) {
155+ this . __throwLockNotOwned ( ) ;
156+ }
157+ throw e ;
158+ } ) ;
147159 }
148160
149161 renew ( ) {
150162 return new Promise ( ( resolve , reject ) => {
151- return this . __etcd . set ( this . __key , this . __node_id , {
163+ return this . __etcd . set ( this . __key , null , {
152164 prevValue : this . __node_id ,
153165 refresh : true ,
154166 ttl : this . __ttl
@@ -157,6 +169,12 @@ export default class Microlock extends EventEmitter {
157169 return resolve ( val ) ;
158170 } )
159171 } )
160- . catch ( ( ) => this . __throwLockNotOwned ( ) ) ;
172+ . catch ( ( e ) => {
173+ // KeyNotFound or CompareFailed
174+ if ( e . errorCode === 100 || e . errorCode === 101 ) {
175+ this . __throwLockNotOwned ( ) ;
176+ }
177+ throw e ;
178+ } ) ;
161179 }
162180}
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import Microlock, {
1212 InvalidTtlError ,
1313 AlreadyLockedError ,
1414 LockNotOwnedError
15- } from '../../lib /microlock' ;
15+ } from '../../src /microlock' ;
1616
1717describe ( 'microlock' , ( ) => {
1818 let etcd = null
You can’t perform that action at this time.
0 commit comments