@@ -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,18 @@ 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+ change . d = this . store . get ( change . id ) ;
203+ change . hasSentFullObject = true ;
204+ this . localQueue . queue ( change ) ;
205+ } else {
206+ this . localQueue . dequeueChangesFor ( change . id ) ;
207+ }
208+
209+ break ;
210+ case CODE_EMPTY_RESPONSE : // Change causes no change, just acknowledge it
197211 internal . updateAcknowledged . call ( this , acknowledged ) ;
198212 break ;
199213 default :
@@ -306,7 +320,6 @@ inherits( Channel, EventEmitter );
306320
307321Channel . prototype . handleMessage = function ( data ) {
308322 var message = parseMessage ( data ) ;
309-
310323 this . message . emit ( message . command , message . data ) ;
311324} ;
312325
0 commit comments