mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-10-27 03:02:30 +01:00
tweaks eslint rules, fixes gulp-eslint, adds some comments
This commit is contained in:
@@ -68,12 +68,12 @@
|
||||
"no-this-before-super": 2,
|
||||
"no-var": 2,
|
||||
"object-shorthand": 2,
|
||||
"prefer-const": 2,
|
||||
"prefer-const": 0,
|
||||
"prefer-spread": 2,
|
||||
"prefer-template": 2,
|
||||
"array-bracket-spacing": [2, "never"],
|
||||
"brace-style": [2, "1tbs", { "allowSingleLine": false }],
|
||||
"camel-case": 2,
|
||||
"camelcase": 2,
|
||||
"comma-spacing": 2,
|
||||
"comma-style": [2, "last"],
|
||||
"computed-property-spacing": [2, "never"],
|
||||
@@ -98,7 +98,7 @@
|
||||
"operator-linebreak": [2, "after"],
|
||||
"quote-props": [2, "as-needed", { "keywords": true }],
|
||||
"semi-spacing": [2, {"before": false, "after": true}],
|
||||
"space-after-keyword": 2,
|
||||
"space-after-keywords": 2,
|
||||
"space-before-blocks": 2,
|
||||
"space-before-function-paren": 2,
|
||||
"space-before-keywords": 2,
|
||||
@@ -109,7 +109,7 @@
|
||||
"spaced-comment": [2, "always", { exceptions: ["-"]}],
|
||||
"padded-blocks": [2, "never"],
|
||||
"no-multiple-empty-lines": [2, {max: 2}],
|
||||
"lines-around-comment": [2, { "beforeBlockComment": true, "beforeLineComment": true }]
|
||||
"lines-around-comment": [2, { "beforeBlockComment": true, "beforeLineComment": true, "allowBlockStart": true }]
|
||||
},
|
||||
"env": {
|
||||
"es6": true,
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"cookie-session": "^1.2.0",
|
||||
"coupon-code": "~0.3.0",
|
||||
"domain-middleware": "~0.1.0",
|
||||
"estraverse": "^4.1.1",
|
||||
"express": "~4.13.3",
|
||||
"express-csv": "~0.6.0",
|
||||
"firebase": "^2.2.9",
|
||||
|
||||
@@ -2,7 +2,10 @@ import gulp from 'gulp';
|
||||
import eslint from 'gulp-eslint';
|
||||
|
||||
// TODO lint client
|
||||
// TDOO separate linting cong between
|
||||
// TDOO separate linting cong between
|
||||
// TODO lint gulp tasks, tests, ...?
|
||||
// TODO what about prefer-const rule?
|
||||
// TODO remove estraverse dependency once https://github.com/adametry/gulp-eslint/issues/117 sorted out
|
||||
gulp.task('lint:server', () => {
|
||||
// Ignore .coffee files
|
||||
return gulp
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Base class for custom application errors
|
||||
// It extends Error and capture the stack trace
|
||||
class CustomError extends Error {
|
||||
constructor() {
|
||||
constructor () {
|
||||
super();
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ class CustomError extends Error {
|
||||
// NotAuthorized error with a 401 http error code
|
||||
// used when a request is not authorized
|
||||
class NotAuthorized extends CustomError {
|
||||
constructor(customMessage) {
|
||||
constructor (customMessage) {
|
||||
super();
|
||||
this.name = this.constructor.name;
|
||||
this.httpCode = 401;
|
||||
@@ -24,7 +24,7 @@ class NotAuthorized extends CustomError {
|
||||
// used for requests not formatted correctly
|
||||
// TODO use for validation errors too?
|
||||
class BadRequest extends CustomError {
|
||||
constructor(customMessage) {
|
||||
constructor (customMessage) {
|
||||
super();
|
||||
this.name = this.constructor.name;
|
||||
this.httpCode = 400;
|
||||
@@ -35,7 +35,7 @@ class BadRequest extends CustomError {
|
||||
// InternalError error with a 500 http error code
|
||||
// used when an unexpected, internal server error is thrown
|
||||
class InternalServerError extends CustomError {
|
||||
constructor(customMessage) {
|
||||
constructor (customMessage) {
|
||||
super();
|
||||
this.name = this.constructor.name;
|
||||
this.httpCode = 500;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
let winston = require('winston');
|
||||
let nconf = require('nconf');
|
||||
|
||||
// TODO use const?
|
||||
// TODO use const?
|
||||
// TODO move isProd to a single location
|
||||
let isProd = nconf.get('NODE_ENV') === 'production';
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
// The error handler middleware that handles all errors
|
||||
// The error handler middleware that handles all errors
|
||||
// and respond to the client
|
||||
let logger = require('../../libs/api-v3/logger');
|
||||
let errors = require('../../libs/api-v3/errors');
|
||||
let CustomError = errors.CustomError;
|
||||
let InternalServerError = errors.InternalServerError;
|
||||
|
||||
module.exports = function (err, req, res, next) {
|
||||
module.exports = function errorHandlerMiddleware (err, req, res, next) {
|
||||
// Log the original error with some metadata
|
||||
let stack = err.stack || err.message || err;
|
||||
|
||||
logger.error(stack, {
|
||||
originalUrl: req.originalUrl,
|
||||
headers: req.headers,
|
||||
body: req.body
|
||||
});
|
||||
|
||||
|
||||
// In case of a CustomError class, use it's data
|
||||
// Otherwise try to identify the type of error (mongoose validation, mongodb unique, ...)
|
||||
// If we can't identify it, respond with a generic 500 error
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
let errorHandler = require('./errorHandler');
|
||||
|
||||
module.exports = function (app) {
|
||||
|
||||
module.exports = function attachMiddlewares (app) {
|
||||
// Error handler middleware, define as the last one
|
||||
app.use(errorHandler);
|
||||
};
|
||||
Reference in New Issue
Block a user