express js error handler(s) get ignored after first one
You need to pass error to the other error middleware when you call next like this:
app.use((error: TypeError | AuthError, req: Request, res: Response, next: NextFunction) => {
        console.log("CHECK FOR AUTH ERROR");
        if(error instanceof AuthError) {
            console.log("AUTH ERROR FOUND");
            res.status(403).send({msg: "Authentication failed"});
        } else {
            console.log("NO AUTH ERROR")
            next(error);
        }
    });

Without it, the normal middleware will get called.

I have an express js app with some routes and a protected route that matches all the calls to an endpoint that starts with /app. after that i add generic error handler to the app like so:

app.use("/app", authenticate);

// app.post("/new_user", validate({body: schema}), route_handler);
// more routes etc. 

app.use((error: TypeError | ValidationError, req: Request, res: Response, next: NextFunction) => {
        console.log("CHECK FOR VALIDATION ERROR");
        if(error instanceof ValidationError) {
            console.log("VALIDATION ERROR FOUND")
            res.status(403).send(error);
        } else {
            console.log("NO VALIDATION ERROR")
            next();
        }
    });

    app.use((error: TypeError | AuthError, req: Request, res: Response, next: NextFunction) => {
        console.log("CHECK FOR AUTH ERROR");
        if(error instanceof AuthError) {
            console.log("AUTH ERROR FOUND");
            res.status(403).send({msg: "Authentication failed"});
        } else {
            console.log("NO AUTH ERROR")
            next();
        }
    });

    app.use((error: Error, req: Request, res: Response, next: NextFunction) => {
        console.log("CHECK GENERIC ERROR");
        if(error) {
            res.status(500).send({msg: "Some generic error happend"});
        } else {
            next();
        }
    });

    app.use((req: Request, res: Response, next: NextFunction) => {
        console.log("ROUTE NOT FOUND");
        res.status(404).send({
            msg: "this endpoint was not found",
        });

        next();
    });

When i do a request to for example the following endpoint: https://localhost/app/ and throw a AuthError on purpose in this endpoint the only console.log()'s i ever see are:
CHECK FOR VALIDATION ERROR
NO VALIDATION ERROR
ROUTE NOT FOUND
But i think i should see the following:
CHECK FOR VALIDATION ERROR
NO VALIDATION ERROR
CHECK FOR AUTH ERROR
AUTH ERROR FOUND
Why is my Auth error middleware never called??
