JavaScript

Usitha Suweeraka
Usitha Suweeraka
6,682 Points

How to add a Not found error when user gave a wrong number?

I coded like below,

router.get('/:id', (req, res, next) => {
    // var type = "type anything";
    // console.log(req.params);
    const side = req.query.side;
    const id = req.params.id;

    if (id > cards.length) {
        const err = new Error('Question Not Found');
        err.status = 404;
        next(err);
    }

But it is not working.. Can anyone help me out?