Skip to content
Advertisement

Error: Route.post() requires a callback function but got a [object Promise]

I am creating a REST API with express, folowing are my architecture,a router is calling a controller.but I got this error, please help me

JavaScript

/////// EmailLogin.js middleware Handler

JavaScript

I’m trying to call it in my router, like this:

/////// Router.js

JavaScript

/////// App.js

JavaScript

What could I do ? is it possible to get a Promise Result in the Router as a Handler?

Advertisement

Answer

@turkdev Change your email login function to this

JavaScript

The problem was earlier, you were assigning it to method wrapRoute() which returns a Promise, which was not settled, causing the error which you got.

If that was just for calling next() on error, you could always use it in the catch block.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement