Skip to content

Questions: Express next() parameter in a function #4857

@khafidprayoga

Description

@khafidprayoga

When i built auth app

My middlewares:

  • protected (for check token)
  • controllers (to validate body data and interact with services)
  • exceptions (sent error status to client if internal error thrown)

when i use next(id) on protected middleware it throws and error and skip controllers.
It goes to exceptions middleware (skip the controllers). In my case i need pass id to the expected contollers but it gives error.

and work excatly as expected, when i change my code to

try{
    const {id} = await verifyToken()
    req.id = id
    next()
}catch(error){
    next(error)
}

My question:
if i pass a parameter to next() interface, does it redirect to express internal error handler? even if i dont use try-catch statements

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions