apps: add detail to http error messages

This commit is contained in:
Girish Ramakrishnan
2019-09-01 17:44:24 -07:00
parent d2f38c1abc
commit d59c1f53b9
4 changed files with 67 additions and 86 deletions

View File

@@ -42,6 +42,7 @@ exports = module.exports = {
getAppConfig: getAppConfig,
getDataDir: getDataDir,
getIconPath: getIconPath,
downloadFile: downloadFile,
uploadFile: uploadFile,
@@ -142,7 +143,7 @@ function AppsError(reason, errorOrMessage, details) {
this.nestedError = errorOrMessage;
}
if (details) _.extend(this, details);
if (details) error.details = details;
}
util.inherits(AppsError, Error);
AppsError.INTERNAL_ERROR = 'Internal Error';
@@ -199,7 +200,7 @@ function validatePortBindings(portBindings, manifest) {
const hostPort = portBindings[portName];
if (!Number.isInteger(hostPort)) return new AppsError(AppsError.BAD_FIELD, `${hostPort} is not an integer`);
if (RESERVED_PORTS.indexOf(hostPort) !== -1) return new AppsError(AppsError.PORT_RESERVED, String(hostPort));
if (RESERVED_PORTS.indexOf(hostPort) !== -1) return new AppsError(AppsError.PORT_RESERVED, `Port ${hostPort} is reserved.`);
if (hostPort <= 1023 || hostPort > 65535) return new AppsError(AppsError.BAD_FIELD, `${hostPort} is not in permitted range`);
}
@@ -379,7 +380,7 @@ function getDuplicateErrorDetails(errorMessage, location, domainObject, portBind
// check if any of the port bindings conflict
for (let portName in portBindings) {
if (portBindings[portName] === parseInt(match[1])) return new AppsError(AppsError.PORT_CONFLICT, match[1]);
if (portBindings[portName] === parseInt(match[1])) return new AppsError(AppsError.PORT_CONFLICT, `Port ${match[1]} is reserved`);
}
return new AppsError(AppsError.ALREADY_EXISTS, `${match[2]} '${match[1]}' is in use`);
@@ -436,6 +437,22 @@ function getIconUrlSync(app) {
return null;
}
function getIconPath(appId, options, callback) {
assert.strictEqual(typeof appId, 'string');
assert.strictEqual(typeof options, 'object');
assert.strictEqual(typeof callback, 'function');
if (!options.original) {
const userIconPath = `${paths.APP_ICONS_DIR}/${appId}.user.png`;
if (safe.fs.existsSync(userIconPath)) return callback(null, userIconPath);
}
const appstoreIconPath = `${paths.APP_ICONS_DIR}/${appId}.png`;
if (safe.fs.existsSync(appstoreIconPath)) return callback(null, appstoreIconPath);
callback(new AppsError(AppsError.NOT_FOUND, 'No icon'));
}
function postProcess(app, domainObjectMap) {
let result = {};
for (let portName in app.portBindings) {