Move UpdaterError to BoxError

This commit is contained in:
Girish Ramakrishnan
2019-10-23 09:39:26 -07:00
parent d0e6b6bfe4
commit e2388b7d88
3 changed files with 24 additions and 52 deletions

View File

@@ -27,8 +27,7 @@ let assert = require('assert'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
updater = require('../updater.js'),
updateChecker = require('../updatechecker.js'),
UpdaterError = require('../updater.js').UpdaterError;
updateChecker = require('../updatechecker.js');
function toHttpError(error) {
switch (error.reason) {
@@ -79,8 +78,8 @@ function update(req, res, next) {
// this only initiates the update, progress can be checked via the progress route
updater.updateToLatest(req.body, auditSource.fromRequest(req), function (error, taskId) {
if (error && error.reason === UpdaterError.ALREADY_UPTODATE) return next(new HttpError(422, error.message));
if (error && error.reason === UpdaterError.BAD_STATE) return next(new HttpError(409, error.message));
if (error && error.reason === BoxError.NOT_FOUND) return next(new HttpError(422, error.message));
if (error && error.reason === BoxError.BAD_STATE) return next(new HttpError(409, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(202, { taskId }));