diff --git a/src/apps.js b/src/apps.js index 69413fade..6a837abed 100644 --- a/src/apps.js +++ b/src/apps.js @@ -63,10 +63,6 @@ exports = module.exports = { PORT_TYPE_TCP: 'tcp', PORT_TYPE_UDP: 'udp', - // error codes - ETASK_STOPPED: 'task_stopped', // user stopped a task - ETASK_CRASHED: 'task_crashed', // apptask crashed - // installation codes (keep in sync in UI) ISTATE_PENDING_INSTALL: 'pending_install', // installs and fresh reinstalls ISTATE_PENDING_CLONE: 'pending_clone', // clone @@ -110,6 +106,7 @@ var appdb = require('./appdb.js'), async = require('async'), backups = require('./backups.js'), BackupsError = backups.BackupsError, + BoxError = require('./boxerror.js'), constants = require('./constants.js'), DatabaseError = require('./databaseerror.js'), debug = require('debug')('box:apps'), @@ -647,8 +644,8 @@ function scheduleTask(appId, args, values, callback) { debug(`scheduleTask: task ${taskId} of $${appId} completed`); if (error && (error.code === tasks.ECRASHED || error.code === tasks.ESTOPPED)) { // if task crashed, update the error debug(`Apptask crashed/stopped: ${error.message}`); - const code = error.crashed ? exports.ETASK_CRASHED : exports.ETASK_STOPPED; - appdb.update(appId, { installationState: exports.ISTATE_ERROR, error: { code: code, message: error.message }, taskId: null }, NOOP_CALLBACK); + const crashed = error.code === tasks.ECRASHED, stopped = error.code === tasks.ESTOPPED; + appdb.update(appId, { installationState: exports.ISTATE_ERROR, error: { reason: BoxError.TASK_ERROR, crashed, stopped, message: error.message }, taskId: null }, NOOP_CALLBACK); } else if (values.installationState !== exports.ISTATE_PENDING_UNINSTALL) { // clear out taskId since it's done appdb.update(appId, { taskId: null }, NOOP_CALLBACK); } diff --git a/src/boxerror.js b/src/boxerror.js index f76561919..6a3d74e02 100644 --- a/src/boxerror.js +++ b/src/boxerror.js @@ -45,6 +45,7 @@ BoxError.LOGROTATE_ERROR = 'Logrotate Error'; BoxError.NETWORK_ERROR = 'Network Error'; BoxError.NOT_FOUND = 'Not found'; BoxError.REVERSEPROXY_ERROR = 'ReverseProxy Error'; +BoxError.TASK_ERROR = 'Task Error'; BoxError.prototype.toPlainObject = function () { return _.extend({}, { message: this.message, reason: this.reason }, this.details);