Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions server/src/controller/item.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import cloudinary from "cloudinary";
import cloudinaryStorage from "multer-storage-cloudinary";
import config from "../config";
import VerifyToken from "../_helper/VerifyToken";
// import AppError from "../utils/appError";
// import catchAsync from "../utils/catchAsync";

const router = express.Router();
router.use(bodyParser.urlencoded({ extended: true }));
Expand Down Expand Up @@ -86,6 +88,12 @@ router.get("/:id", async (req, res) => {
}
});

// router.get("/:id", catchAsync(async (req, res) => {
// const item = await getItem(req.params.id);
// if (!item) return next(new AppError('No item found', 404));
// res.status(200).send(item);
// }));

// RETURNS ALL THE ITEMS IN THE DATABASE
router.get("/", async (req, res) => {
try {
Expand Down
13 changes: 13 additions & 0 deletions server/src/utils/appError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class AppError extends Error {
constructor(message, statusCode) {
super(message);
this.statusCode = statusCode;

this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error';
this.isOperational = true;

Error.captureStackTrace(this, this.constructor);
}
}

module.exports = AppError;
7 changes: 7 additions & 0 deletions server/src/utils/catchAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//Catching error in async functions to avoid using the try catch block everywhere
module.exports = fn => {
return (req, res, next) => {
fn(req, res, next).catch(next);
}
}