Move EventLogError to BoxError

This commit is contained in:
Girish Ramakrishnan
2019-10-22 13:59:01 -07:00
parent 88818a1ec2
commit 9842b6d4a1
3 changed files with 25 additions and 39 deletions

View File

@@ -5,15 +5,24 @@ exports = module.exports = {
list: list
};
var eventlog = require('../eventlog.js'),
EventLogError = eventlog.EventLogError,
var BoxError = require('../boxerror.js'),
eventlog = require('../eventlog.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 && error.reason === EventLogError.NOT_FOUND) return next(new HttpError(404, 'no such eventlog'));
if (error) return next(new HttpError(500, error));
if (error) return next(toHttpError(error));
next(new HttpSuccess(200, { event: result }));
});
@@ -34,7 +43,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(new HttpError(500, error));
if (error) return next(toHttpError(error));
next(new HttpSuccess(200, { eventlogs: result }));
});