diff --git a/src/errors/ApiError.js b/src/errors/ApiError.js index c5edac0..c2dd9fe 100644 --- a/src/errors/ApiError.js +++ b/src/errors/ApiError.js @@ -4,5 +4,7 @@ class ApiError { this.code = code; } } - +// Is this class doing anything besides receiving data? what is the return? +// Take a look at this Method in the Erro object: Error.captureStackTrace(this); +// Also, read this: https://stackoverflow.com/questions/59625425/understanding-error-capturestacktrace-and-stack-trace-persistance export default ApiError; diff --git a/src/middlewares/handleErrors.js b/src/middlewares/handleErrors.js index 3fddfa3..fc9c826 100644 --- a/src/middlewares/handleErrors.js +++ b/src/middlewares/handleErrors.js @@ -2,6 +2,7 @@ import ApiError from '../errors/ApiError'; export default function ErrorHandler(error, req, res, next) { + //Ok, now I got why you created the de ApiError class. I thought you were going to throw the stack traces. You may "ignore" what I commented, but don't forget to read about it. if (error instanceof ApiError) { return res.status(error.code).send({ error: { diff --git a/src/routes/photos.routes.js b/src/routes/photos.routes.js index 75c0394..13fd6bf 100644 --- a/src/routes/photos.routes.js +++ b/src/routes/photos.routes.js @@ -17,7 +17,9 @@ const upload = multer({ || file.mimetype === 'image/jpeg' ) { cb(null, true); + // try to always avoid the use of "else" statement. In this case you can just return cb(null, true) } else { + // Why do you declare cb(null,false), and right after return it differently (as an ApiError instance)? cb(null, false); return cb(new ApiError(400, 'Only .png, .jpg and .jpeg format allowed!')); } diff --git a/src/validation/post.js b/src/validation/post.js index 9006baa..ab23476 100644 --- a/src/validation/post.js +++ b/src/validation/post.js @@ -1,5 +1,5 @@ import Joi from '@hapi/joi'; - +// Switch it 'npm install joi' const createPhoto = Joi.object({ caption: Joi.string().min(1).max(266).trim() .required(),