diff --git a/package.json b/package.json index 1bb77c8..ea14c6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "endo-core", - "version": "18.1.0", + "version": "18.2.0", "description": "Put some description here", "keywords": [], "homepage": "https://github.com/octoblu/endo-core", diff --git a/src/config-generators/status-device-create-config-generator.coffee b/src/config-generators/status-device-create-config-generator.coffee index 3857304..919adb9 100644 --- a/src/config-generators/status-device-create-config-generator.coffee +++ b/src/config-generators/status-device-create-config-generator.coffee @@ -19,7 +19,5 @@ module.exports = ({userDeviceUuid, authorizedUuid}) -> {uuid: userDeviceUuid} {uuid: authorizedUuid} ] - errors: [] status: - errors: - $ref: '#/errors' + errors: [] diff --git a/src/services/messages-service.coffee b/src/services/messages-service.coffee index e50dc67..73d2d92 100644 --- a/src/services/messages-service.coffee +++ b/src/services/messages-service.coffee @@ -43,17 +43,16 @@ class MessagesService return callback newError if newError? @_updateStatusDeviceWithError {auth, senderUuid, userDeviceUuid, error, respondTo}, callback - _updateStatusDeviceWithError: ({auth, senderUuid, userDeviceUuid, error, respondTo}, callback) => + _updateStatusDeviceWithError: (options, callback) => + {auth, senderUuid, userDeviceUuid, error, respondTo, alreadyTried} = options + meshblu = new MeshbluHTTP _.defaults auth, @meshbluConfig meshblu.device userDeviceUuid, (newError, {statusDevice}={}) => return callback() if newError? return callback() unless statusDevice? update = - $set: - 'status.errors': - $ref: '#/errors' $push: - errors: + 'status.errors': $each: [ senderUuid: senderUuid date: moment.utc().format() @@ -63,7 +62,18 @@ class MessagesService message: error.message ] $slice: -99 - meshblu.updateDangerously statusDevice, update, as: userDeviceUuid, callback + + meshblu.updateDangerously statusDevice, update, as: userDeviceUuid, (error) => + return callback() unless error? + return callback error if alreadyTried + + if _.includes error.message, 'must be an array but is of type' + meshblu.updateDangerously statusDevice, {$set: 'status.errors': []}, (error) => + return callback error if error? + newOptions = _.defaults {alreadyTried: true}, options + return @_updateStatusDeviceWithError newOptions, callback + + return callback error responseSchema: (callback) => @messageHandler.responseSchema callback diff --git a/test/integration/message-spec.coffee b/test/integration/message-spec.coffee index abfbbb1..02b8846 100644 --- a/test/integration/message-spec.coffee +++ b/test/integration/message-spec.coffee @@ -431,11 +431,8 @@ describe 'messages', -> .set 'Authorization', "Basic #{@credentialsDeviceAuth}" .set 'x-meshblu-as', 'user-uuid' .send - $set: - 'status.errors': - $ref: '#/errors' $push: - errors: + 'status.errors': $each: [ code: 500 message: 'Something very bad happened' diff --git a/test/integration/user-devices-spec.coffee b/test/integration/user-devices-spec.coffee index 9234ee6..a657a89 100644 --- a/test/integration/user-devices-spec.coffee +++ b/test/integration/user-devices-spec.coffee @@ -301,10 +301,9 @@ describe 'User Devices Spec', -> {uuid: 'user_device_uuid'} {uuid: 'some-uuid'} ] - errors: [] + status: - errors: - $ref: '#/errors' + errors: [] .reply 201, uuid: 'status-device-uuid', token: 'status-device-token' @updateUserStatusDevice = @meshblu