From abcc75a6f2a4947c49efad82a223aadb7ca02169 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Tue, 24 Jun 2014 09:43:14 -0700 Subject: [PATCH] A bit of error logging for #1220. --- app/models/CocoModel.coffee | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/CocoModel.coffee b/app/models/CocoModel.coffee index e2cefa09d..dd6ce23cf 100644 --- a/app/models/CocoModel.coffee +++ b/app/models/CocoModel.coffee @@ -64,7 +64,7 @@ class CocoModel extends Backbone.Model @backedUp = {} schema: -> return @constructor.schema - + getValidationErrors: -> errors = tv4.validateMultiple(@attributes, @constructor.schema or {}).errors return errors if errors?.length @@ -76,7 +76,7 @@ class CocoModel extends Backbone.Model for error in errors console.debug "\t", error.dataPath, ":", error.message return errors - + save: (attrs, options) -> options ?= {} 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 @trigger "save", @ return super attrs, options - + patch: (options) -> return false unless @_revertAttributes options ?= {} options.patch = true - + attrs = {_id: @id} keys = [] for key in _.keys @attributes unless _.isEqual @attributes[key], @_revertAttributes[key] attrs[key] = @attributes[key] keys.push key - + return unless keys.length console.debug 'Patching', @get('name') or @, keys @save(attrs, options) @@ -207,7 +207,10 @@ class CocoModel extends Backbone.Model applyDelta: (delta) -> 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 getExpandedDelta: ->