Refactor toHttpError code into BoxError
This commit is contained in:
@@ -10,19 +10,9 @@ var BoxError = require('../boxerror.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess;
|
||||
|
||||
function toHttpError(error) {
|
||||
switch (error.reason) {
|
||||
case BoxError.NOT_FOUND:
|
||||
return new HttpError(404, error);
|
||||
case BoxError.DATABASE_ERROR:
|
||||
default:
|
||||
return new HttpError(500, error);
|
||||
}
|
||||
}
|
||||
|
||||
function get(req, res, next) {
|
||||
eventlog.get(req.params.eventId, function (error, result) {
|
||||
if (error) return next(toHttpError(error));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { event: result }));
|
||||
});
|
||||
@@ -43,7 +33,7 @@ function list(req, res, next) {
|
||||
if (req.query.action) actions.push(req.query.action);
|
||||
|
||||
eventlog.getAllPaged(actions, req.query.search || null, page, perPage, function (error, result) {
|
||||
if (error) return next(toHttpError(error));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { eventlogs: result }));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user