A bit of error logging for .

This commit is contained in:
Nick Winter 2014-06-24 09:43:14 -07:00
parent 3862bd2376
commit abcc75a6f2

View file

@ -64,7 +64,7 @@ class CocoModel extends Backbone.Model
@backedUp = {} @backedUp = {}
schema: -> return @constructor.schema schema: -> return @constructor.schema
getValidationErrors: -> getValidationErrors: ->
errors = tv4.validateMultiple(@attributes, @constructor.schema or {}).errors errors = tv4.validateMultiple(@attributes, @constructor.schema or {}).errors
return errors if errors?.length return errors if errors?.length
@ -76,7 +76,7 @@ class CocoModel extends Backbone.Model
for error in errors for error in errors
console.debug "\t", error.dataPath, ":", error.message console.debug "\t", error.dataPath, ":", error.message
return errors return errors
save: (attrs, options) -> save: (attrs, options) ->
options ?= {} options ?= {}
options.headers ?= {} options.headers ?= {}
@ -97,19 +97,19 @@ class CocoModel extends Backbone.Model
noty text: "#{errorMessage}: #{res.status} #{res.statusText}", layout: 'topCenter', type: 'error', killer: false, timeout: 10000 noty text: "#{errorMessage}: #{res.status} #{res.statusText}", layout: 'topCenter', type: 'error', killer: false, timeout: 10000
@trigger "save", @ @trigger "save", @
return super attrs, options return super attrs, options
patch: (options) -> patch: (options) ->
return false unless @_revertAttributes return false unless @_revertAttributes
options ?= {} options ?= {}
options.patch = true options.patch = true
attrs = {_id: @id} attrs = {_id: @id}
keys = [] keys = []
for key in _.keys @attributes for key in _.keys @attributes
unless _.isEqual @attributes[key], @_revertAttributes[key] unless _.isEqual @attributes[key], @_revertAttributes[key]
attrs[key] = @attributes[key] attrs[key] = @attributes[key]
keys.push key keys.push key
return unless keys.length return unless keys.length
console.debug 'Patching', @get('name') or @, keys console.debug 'Patching', @get('name') or @, keys
@save(attrs, options) @save(attrs, options)
@ -207,7 +207,10 @@ class CocoModel extends Backbone.Model
applyDelta: (delta) -> applyDelta: (delta) ->
newAttributes = $.extend(true, {}, @attributes) newAttributes = $.extend(true, {}, @attributes)
jsondiffpatch.patch newAttributes, delta try
jsondiffpatch.patch newAttributes, delta
catch error
console.error "Error applying delta", delta, "to attributes", newAttributes, error
@set newAttributes @set newAttributes
getExpandedDelta: -> getExpandedDelta: ->