From f8d2398d5ed28a74009c89c76e80a7a617232e4c Mon Sep 17 00:00:00 2001 From: Samuel Botelho <30642802+samuelfbtlh@users.noreply.github.com> Date: Sun, 5 Sep 2021 14:44:07 -0300 Subject: [PATCH 1/5] Update post.js --- src/validation/post.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(), From 038f1686168984604184c34b97bfb23db9c54c9c Mon Sep 17 00:00:00 2001 From: Samuel Botelho <30642802+samuelfbtlh@users.noreply.github.com> Date: Sun, 5 Sep 2021 14:47:49 -0300 Subject: [PATCH 2/5] Update ApiError.js --- src/errors/ApiError.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/errors/ApiError.js b/src/errors/ApiError.js index c5edac0..75cb777 100644 --- a/src/errors/ApiError.js +++ b/src/errors/ApiError.js @@ -4,5 +4,5 @@ class ApiError { this.code = code; } } - +// Is this class doing anything besides receiving data? what is the return? export default ApiError; From 0f6ae6a54c09ac64b2a6a3ca8d1b5930f98f1fe9 Mon Sep 17 00:00:00 2001 From: Samuel Botelho <30642802+samuelfbtlh@users.noreply.github.com> Date: Sun, 5 Sep 2021 14:50:03 -0300 Subject: [PATCH 3/5] Update ApiError.js --- src/errors/ApiError.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/errors/ApiError.js b/src/errors/ApiError.js index 75cb777..c2dd9fe 100644 --- a/src/errors/ApiError.js +++ b/src/errors/ApiError.js @@ -5,4 +5,6 @@ class ApiError { } } // 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; From 78e1cd3d74ab81a7a56a47dfb872819f1e46f029 Mon Sep 17 00:00:00 2001 From: Samuel Botelho <30642802+samuelfbtlh@users.noreply.github.com> Date: Sun, 5 Sep 2021 14:53:46 -0300 Subject: [PATCH 4/5] Update handleErrors.js --- src/middlewares/handleErrors.js | 1 + 1 file changed, 1 insertion(+) 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: { From 3a19b297ed05c1369e586edd1c92f3aee952b49b Mon Sep 17 00:00:00 2001 From: Samuel Botelho <30642802+samuelfbtlh@users.noreply.github.com> Date: Sun, 5 Sep 2021 15:03:09 -0300 Subject: [PATCH 5/5] Update photos.routes.js --- src/routes/photos.routes.js | 2 ++ 1 file changed, 2 insertions(+) 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!')); }