Refactor toHttpError code into BoxError
This commit is contained in:
@@ -29,19 +29,6 @@ let assert = require('assert'),
|
||||
updater = require('../updater.js'),
|
||||
updateChecker = require('../updatechecker.js');
|
||||
|
||||
function toHttpError(error) {
|
||||
switch (error.reason) {
|
||||
case BoxError.NOT_FOUND:
|
||||
return new HttpError(404, error);
|
||||
case BoxError.BAD_STATE:
|
||||
return new HttpError(409, error);
|
||||
case BoxError.DATABASE_ERROR:
|
||||
case BoxError.INTERNAL_ERROR:
|
||||
default:
|
||||
return new HttpError(500, error);
|
||||
}
|
||||
}
|
||||
|
||||
function reboot(req, res, next) {
|
||||
// Finish the request, to let the appstore know we triggered the reboot
|
||||
next(new HttpSuccess(202, {}));
|
||||
@@ -51,7 +38,7 @@ function reboot(req, res, next) {
|
||||
|
||||
function isRebootRequired(req, res, next) {
|
||||
cloudron.isRebootRequired(function (error, result) {
|
||||
if (error) return next(toHttpError(error));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { rebootRequired: result }));
|
||||
});
|
||||
@@ -59,7 +46,7 @@ function isRebootRequired(req, res, next) {
|
||||
|
||||
function getConfig(req, res, next) {
|
||||
cloudron.getConfig(function (error, cloudronConfig) {
|
||||
if (error) return next(toHttpError(error));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, cloudronConfig));
|
||||
});
|
||||
@@ -67,7 +54,7 @@ function getConfig(req, res, next) {
|
||||
|
||||
function getDisks(req, res, next) {
|
||||
disks.getDisks(function (error, result) {
|
||||
if (error) return next(toHttpError(error));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, result));
|
||||
});
|
||||
@@ -115,7 +102,7 @@ function getLogs(req, res, next) {
|
||||
};
|
||||
|
||||
cloudron.getLogs(req.params.unit, options, function (error, logStream) {
|
||||
if (error) return next(toHttpError(error));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/x-logs',
|
||||
@@ -144,7 +131,7 @@ function getLogStream(req, res, next) {
|
||||
};
|
||||
|
||||
cloudron.getLogs(req.params.unit, options, function (error, logStream) {
|
||||
if (error) return next(toHttpError(error));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/event-stream',
|
||||
@@ -170,7 +157,7 @@ function setDashboardAndMailDomain(req, res, next) {
|
||||
if (!custom.spec().domains.changeDashboardDomain) return next(new HttpError(405, 'feature disabled by admin'));
|
||||
|
||||
cloudron.setDashboardAndMailDomain(req.body.domain, auditSource.fromRequest(req), function (error) {
|
||||
if (error) return next(toHttpError(error));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204, {}));
|
||||
});
|
||||
@@ -182,7 +169,7 @@ function prepareDashboardDomain(req, res, next) {
|
||||
if (!custom.spec().domains.changeDashboardDomain) return next(new HttpError(405, 'feature disabled by admin'));
|
||||
|
||||
cloudron.prepareDashboardDomain(req.body.domain, auditSource.fromRequest(req), function (error, taskId) {
|
||||
if (error) return next(toHttpError(error));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, { taskId }));
|
||||
});
|
||||
@@ -190,7 +177,7 @@ function prepareDashboardDomain(req, res, next) {
|
||||
|
||||
function renewCerts(req, res, next) {
|
||||
cloudron.renewCerts({ domain: req.body.domain || null }, auditSource.fromRequest(req), function (error, taskId) {
|
||||
if (error) return next(toHttpError(error));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, { taskId }));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user