Add proper error codes

This commit is contained in:
Girish Ramakrishnan
2019-08-30 12:42:38 -07:00
parent c22cdb8d81
commit 4fd04fa349

View File

@@ -49,6 +49,10 @@ 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
// exported for testing
_validatePortBindings: validatePortBindings,
_validateAccessRestriction: validateAccessRestriction,
@@ -599,7 +603,8 @@ function scheduleTask(appId, args, values, callback) {
debug(`scheduleTask: task ${taskId} of $${appId} completed`);
if (error && (error.crashed || error.stopped)) {
debug(`Apptask crashed/stopped: ${error.message}`);
appdb.update(appId, { installationState: appdb.ISTATE_ERROR, error: { message: error.message }, taskId: null }, NOOP_CALLBACK);
const code = error.crashed ? exports.ETASK_CRASHED : exports.ETASK_STOPPED;
appdb.update(appId, { installationState: appdb.ISTATE_ERROR, error: { code: code, message: error.message }, taskId: null }, NOOP_CALLBACK);
} else if (values.installationState !== appdb.ISTATE_PENDING_UNINSTALL) {
appdb.update(appId, { taskId: null }, NOOP_CALLBACK);
}