Skip to content

Commit

Permalink
Use error handling package
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Buczynski committed Jul 17, 2016
1 parent 5f24ca6 commit 58936cc
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 218 deletions.
6 changes: 3 additions & 3 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let bodyParser = require('body-parser');
let compression = require('compression');
let serveStatic = require('serve-static');
let cookieParser = require('cookie-parser');
let errorMiddleware = require('meanie-express-error-middleware');
let errors = require('meanie-express-error-handling');
let jwt = require('meanie-express-jwt-service');
let router = require('./services/router');
let db = require('./services/db');
Expand Down Expand Up @@ -120,8 +120,8 @@ module.exports = function() {
router(app);

//Create error handling middleware stack
errorMiddleware
.load(ERROR_MIDDLEWARE.concat(['auth-clear-cookie', 'send']))
errors
.middleware(ERROR_MIDDLEWARE.concat(['auth-clear-cookie', 'send']))
.forEach(handler => app.use(handler));

//Return express server instance
Expand Down
8 changes: 4 additions & 4 deletions app/components/auth/auth.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
let passport = require('passport');
let moment = require('moment');
let jwt = require('meanie-express-jwt-service');
let types = require('meanie-express-error-types');
let NotAuthenticatedError = types.NotAuthenticatedError;
let NotAuthorizedError = types.NotAuthorizedError;
let UserSuspendedError = types.UserSuspendedError;
let errors = require('meanie-express-error-handling');
let NotAuthenticatedError = errors.NotAuthenticatedError;
let NotAuthorizedError = errors.NotAuthorizedError;
let UserSuspendedError = errors.UserSuspendedError;

/**
* To camel case
Expand Down
4 changes: 2 additions & 2 deletions app/components/error/error.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* Dependencies
*/
let types = require('meanie-express-error-types');
let ReportedError = types.ReportedError;
let errors = require('meanie-express-error-handling');
let ReportedError = errors.ReportedError;

/**
* Error controller
Expand Down
49 changes: 0 additions & 49 deletions app/components/error/handler.js

This file was deleted.

67 changes: 0 additions & 67 deletions app/components/error/middleware/issue-on-github.js

This file was deleted.

9 changes: 4 additions & 5 deletions app/components/file/file.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
*/
let multer = require('multer');
let mimeTypesFilter = require('meanie-multer-mime-types-filter');
let types = require('meanie-express-error-types');
let BadRequestError = types.BadRequestError;
let FileTooLargeError = types.FileTooLargeError;
let errorHandler = require('../error/handler');
let errors = require('meanie-express-error-handling');
let BadRequestError = errors.BadRequestError;
let FileTooLargeError = errors.FileTooLargeError;
let gcloud = require('../../services/gcloud');
let gcs = gcloud.storage();

Expand Down Expand Up @@ -131,7 +130,7 @@ module.exports = {
//Delete the file (allow failures but log errors)
gcsFile.delete(error => {
if (error) {
errorHandler(error, req);
errors.handler(error, req);
}
next();
});
Expand Down
3 changes: 2 additions & 1 deletion app/components/user/avatar.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
let multer = require('multer');
let mimeTypesFilter = require('meanie-multer-mime-types-filter');
let NotFoundError = require('meanie-express-error-types').NotFoundError;
let errors = require('meanie-express-error-handling');
let NotFoundError = errors.NotFoundError;

/**
* Avatar URL generator
Expand Down
17 changes: 8 additions & 9 deletions app/components/user/user.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/
let mongoose = require('mongoose');
let jwt = require('meanie-express-jwt-service');
let types = require('meanie-express-error-types');
let NotFoundError = types.NotFoundError;
let BadRequestError = types.BadRequestError;
let InvalidTokenError = types.InvalidTokenError;
let errorHandler = require('../error/handler');
let errors = require('meanie-express-error-handling');
let NotFoundError = errors.NotFoundError;
let BadRequestError = errors.BadRequestError;
let InvalidTokenError = errors.InvalidTokenError;
let mailer = require('../../services/mailer');

/**
Expand Down Expand Up @@ -50,7 +49,7 @@ module.exports = {
.then(user => {
verifyEmailAddressEmail(user)
.then(email => mailer.send(email))
.catch(error => errorHandler(error, req));
.catch(error => errors.handler(error, req));
return (req.user = user);
})
.then(user => {
Expand Down Expand Up @@ -85,7 +84,7 @@ module.exports = {
if (isEmailChanged) {
verifyEmailAddressEmail(user)
.then(email => mailer.send(email))
.catch(error => errorHandler(error, req));
.catch(error => errors.handler(error, req));
}
return (req.user = user);
})
Expand All @@ -111,7 +110,7 @@ module.exports = {
.then(user => {
passwordHasChangedEmail(user)
.then(email => mailer.send(email))
.catch(error => errorHandler(error, req));
.catch(error => errors.handler(error, req));
res.end();
})
.catch(next);
Expand Down Expand Up @@ -183,7 +182,7 @@ module.exports = {
.then(user => {
passwordHasChangedEmail(user)
.then(email => mailer.send(email))
.catch(error => errorHandler(error, req));
.catch(error => errors.handler(error, req));
res.end();
})
.catch(next);
Expand Down
4 changes: 2 additions & 2 deletions app/components/user/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Dependencies
*/
let mongoose = require('mongoose');
let types = require('meanie-express-error-types');
let InvalidTokenError = types.InvalidTokenError;
let errors = require('meanie-express-error-handling');
let InvalidTokenError = errors.InvalidTokenError;

/**
* Models
Expand Down
71 changes: 0 additions & 71 deletions app/services/github.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/services/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ let fs = require('fs');
let path = require('path');
let Promise = require('bluebird');
let sendgrid = require('sendgrid');
let types = require('meanie-express-error-types');
let errors = require('meanie-express-error-handling');
let readFile = Promise.promisify(fs.readFile);
let SendMailError = types.SendMailError;
let SendMailError = errors.SendMailError;
let config = require('../config');

/**
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@
"entities": "^1.1.1",
"express": "^4.13.4",
"gcloud": "^0.34.0",
"github": "^1.1.2",
"glob": "^7.0.3",
"i18n": "^0.6.0",
"meanie-express-error-middleware": "^1.0.2",
"meanie-express-error-types": "^1.0.6",
"meanie-express-error-handling": "^1.0.3",
"meanie-express-github-service": "^1.0.0",
"meanie-express-jwt-service": "^1.0.0",
"meanie-mongoose-only-id": "^1.0.0",
"meanie-mongoose-to-json": "^1.0.1",
Expand Down

0 comments on commit 58936cc

Please sign in to comment.