diff --git a/src/apptask.js b/src/apptask.js index d39420503..dfeffcabb 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -530,8 +530,7 @@ function install(app, restoreConfig, progressCallback, callback) { ], function seriesDone(error) { if (error) { debugApp(app, 'error installing app: %s', error); - const appError = _.extend({ message: error.message, reason: error.reason }, error.details); - return updateApp(app, { installationState: apps.ISTATE_ERROR, error: appError }, callback.bind(null, error)); + return updateApp(app, { installationState: apps.ISTATE_ERROR, error: error.toPlainObject ? error.toPlainObject() : error.message }, callback.bind(null, error)); } callback(null); }); @@ -553,7 +552,8 @@ function backup(app, progressCallback, callback) { ], function seriesDone(error) { if (error) { debugApp(app, 'error backing up app: %s', error); - return updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: { message: error.message } }, callback.bind(null, error)); // return to installed state intentionally + // return to installed state intentionally + return updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: error.toPlainObject ? error.toPlainObject() : error.message }, callback.bind(null, error)); } callback(null); }); @@ -635,7 +635,7 @@ function configure(app, oldConfig, progressCallback, callback) { ], function seriesDone(error) { if (error) { debugApp(app, 'error reconfiguring : %s', error); - return updateApp(app, { installationState: apps.ISTATE_ERROR, error: { message: error.message }}, callback.bind(null, error)); + return updateApp(app, { installationState: apps.ISTATE_ERROR, error: error.toPlainObject ? error.toPlainObject() : error.message }, callback.bind(null, error)); } callback(null); }); @@ -744,7 +744,7 @@ function update(app, updateConfig, progressCallback, callback) { updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: null, health: null }, callback.bind(null, error)); } else if (error) { debugApp(app, 'Error updating app: %s', error); - updateApp(app, { installationState: apps.ISTATE_ERROR, error: { message: error.message }, updateTime: new Date() }, callback.bind(null, error)); + updateApp(app, { installationState: apps.ISTATE_ERROR, error: error.toPlainObject ? error.toPlainObject() : error.message, updateTime: new Date() }, callback.bind(null, error)); } else { if (updateConfig.skipNotification) return callback(); @@ -797,7 +797,7 @@ function uninstall(app, progressCallback, callback) { ], function seriesDone(error) { if (error) { debugApp(app, 'error uninstalling app: %s', error); - return updateApp(app, { installationState: apps.ISTATE_ERROR, error: { message: error.message } }, callback.bind(null, error)); + return updateApp(app, { installationState: apps.ISTATE_ERROR, error: error.toPlainObject ? error.toPlainObject() : error.message }, callback.bind(null, error)); } callback(null); }); diff --git a/src/boxerror.js b/src/boxerror.js index 040ef1a17..5df46af86 100644 --- a/src/boxerror.js +++ b/src/boxerror.js @@ -3,7 +3,8 @@ 'use strict'; const assert = require('assert'), - util = require('util'); + util = require('util'), + _ = require('underscore'); exports = module.exports = BoxError; @@ -36,3 +37,7 @@ BoxError.CONFLICT = 'Conflict'; BoxError.EXTERNAL_ERROR = 'External Error'; BoxError.INTERNAL_ERROR = 'Internal Error'; BoxError.NOT_FOUND = 'Not found'; + +BoxError.prototype.toPlainObject = function () { + return _.extend({}, { message: this.message, reason: this.reason }, this.details); +};