@@ -5,9 +5,12 @@ import { parseMessage, parseVersionMessage, change as change_util } from './util
55import JSONDiff from './jsondiff'
66import uuid from 'node-uuid'
77
8- const jsondiff = new JSONDiff ( { list_diff : false } )
8+ const jsondiff = new JSONDiff ( { list_diff : false } ) ;
99
10- const UNKNOWN_CV = '?'
10+ const UNKNOWN_CV = '?' ;
11+ const CODE_INVALID_VERSION = 405 ;
12+ const CODE_EMPTY_RESPONSE = 412 ;
13+ const CODE_INVALID_DIFF = 440 ;
1114
1215var operation = {
1316 MODIFY : 'M' ,
@@ -193,7 +196,20 @@ internal.applyChange = function( change, ghost ) {
193196
194197internal . handleChangeError = function ( err , change , acknowledged ) {
195198 switch ( err . code ) {
196- case 412 : // Change causes no change, just acknowledge it
199+ case CODE_INVALID_VERSION :
200+ case CODE_INVALID_DIFF : // Invalid version or diff, send full object back to server
201+ if ( ! change . hasSentFullObject ) {
202+ this . store . get ( change . id ) . then ( object => {
203+ change . d = object ;
204+ change . hasSentFullObject = true ;
205+ this . localQueue . queue ( change ) ;
206+ } ) ;
207+ } else {
208+ this . localQueue . dequeueChangesFor ( change . id ) ;
209+ }
210+
211+ break ;
212+ case CODE_EMPTY_RESPONSE : // Change causes no change, just acknowledge it
197213 internal . updateAcknowledged . call ( this , acknowledged ) ;
198214 break ;
199215 default :
@@ -306,7 +322,6 @@ inherits( Channel, EventEmitter );
306322
307323Channel . prototype . handleMessage = function ( data ) {
308324 var message = parseMessage ( data ) ;
309-
310325 this . message . emit ( message . command , message . data ) ;
311326} ;
312327
0 commit comments