Move DisksError to BoxError
This commit is contained in:
+6
-28
@@ -8,34 +8,12 @@ exports = module.exports = {
|
||||
const apps = require('./apps.js'),
|
||||
assert = require('assert'),
|
||||
async = require('async'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
debug = require('debug')('box:disks'),
|
||||
df = require('@sindresorhus/df'),
|
||||
docker = require('./docker.js'),
|
||||
notifications = require('./notifications.js'),
|
||||
paths = require('./paths.js'),
|
||||
util = require('util');
|
||||
|
||||
function DisksError(reason, errorOrMessage) {
|
||||
assert.strictEqual(typeof reason, 'string');
|
||||
assert(errorOrMessage instanceof Error || typeof errorOrMessage === 'string' || typeof errorOrMessage === 'undefined');
|
||||
|
||||
Error.call(this);
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
|
||||
this.name = this.constructor.name;
|
||||
this.reason = reason;
|
||||
if (typeof errorOrMessage === 'undefined') {
|
||||
this.message = reason;
|
||||
} else if (typeof errorOrMessage === 'string') {
|
||||
this.message = errorOrMessage;
|
||||
} else {
|
||||
this.message = 'Internal error';
|
||||
this.nestedError = errorOrMessage;
|
||||
}
|
||||
}
|
||||
util.inherits(DisksError, Error);
|
||||
DisksError.INTERNAL_ERROR = 'Internal Error';
|
||||
DisksError.EXTERNAL_ERROR = 'External Error';
|
||||
paths = require('./paths.js');
|
||||
|
||||
function getDisks(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
@@ -43,7 +21,7 @@ function getDisks(callback) {
|
||||
const dfAsync = async.asyncify(df), dfFileAsync = async.asyncify(df.file);
|
||||
|
||||
docker.info(function (error, info) {
|
||||
if (error) return callback(new DisksError(DisksError.INTERNAL_ERROR, error));
|
||||
if (error) return callback(error);
|
||||
|
||||
async.series([
|
||||
dfAsync,
|
||||
@@ -52,7 +30,7 @@ function getDisks(callback) {
|
||||
dfFileAsync.bind(null, paths.APPS_DATA_DIR),
|
||||
dfFileAsync.bind(null, info.DockerRootDir)
|
||||
], function (error, values) {
|
||||
if (error) return callback(new DisksError(DisksError.INTERNAL_ERROR, error));
|
||||
if (error) return callback(new BoxError(BoxError.FS_ERROR, error));
|
||||
|
||||
// filter by ext4 and then sort to make sure root disk is first
|
||||
const ext4Disks = values[0].filter((r) => r.type === 'ext4').sort((a, b) => a.mountpoint.localeCompare(b.mountpoint));
|
||||
@@ -68,7 +46,7 @@ function getDisks(callback) {
|
||||
};
|
||||
|
||||
apps.getAll(function (error, allApps) {
|
||||
if (error) return callback(new DisksError(DisksError.INTERNAL_ERROR, error));
|
||||
if (error) return callback(new BoxError(BoxError.INTERNAL_ERROR, error));
|
||||
|
||||
async.eachSeries(allApps, function (app, iteratorDone) {
|
||||
if (!app.dataDir) {
|
||||
@@ -81,7 +59,7 @@ function getDisks(callback) {
|
||||
iteratorDone();
|
||||
});
|
||||
}, function (error) {
|
||||
if (error) return callback(new DisksError(DisksError.INTERNAL_ERROR, error));
|
||||
if (error) return callback(new BoxError(BoxError.INTERNAL_ERROR, error));
|
||||
|
||||
callback(null, disks);
|
||||
});
|
||||
|
||||
@@ -56,6 +56,7 @@ function getConfig(req, res, next) {
|
||||
function getDisks(req, res, next) {
|
||||
disks.getDisks(function (error, result) {
|
||||
if (error) return next(new HttpError(500, error));
|
||||
|
||||
next(new HttpSuccess(200, result));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user