Complete the code to create an async middleware wrapper function.
const asyncWrapper = (fn) => (req, res, next) => {
Promise.resolve(fn(req, res, next)).[1](next);
};The catch method is used to handle errors in the async function and pass them to next for Express error handling.
Complete the code to use the async middleware wrapper with an async route handler.
app.get('/data', [1](async (req, res) => { const data = await fetchData(); res.json(data); }));
The asyncWrapper function wraps the async route handler to catch errors and pass them to Express.
Fix the error in the async middleware wrapper to correctly handle errors.
const asyncWrapper = (fn) => (req, res, next) => {
fn(req, res, next).[1](next);
};Directly calling fn(req, res, next) returns a Promise, so catch is needed to handle errors and pass them to next.
Fill both blanks to create an async middleware wrapper that returns a function with correct parameters.
const asyncWrapper = ([1]) => ([2]) => { return Promise.resolve([1](...[2])).catch(next); };
The wrapper takes a function fn and returns a function that takes args (an array of parameters). It calls fn(...args) and catches errors.
Fill all three blanks to create a reusable async middleware wrapper with error forwarding.
function asyncWrapper([1]) { return function [2](req, res, next) { [3](fn(req, res, next)).catch(next); }; }
The function asyncWrapper takes fn, returns a function named middleware that calls Promise.resolve(fn(req, res, next)) and catches errors to pass to next.