First, inside the /home/dli/.d4nyll/.beja/final/code/9/src/handlers/users/create/index.js file, change the return undefined; statement to propagate the error down the promise chain:
return res.json({ message: err.message });
}
throw err;
}).catch(() => {
res.status(500);
Then, add unit tests to src/handlers/users/create/index.unit.test.js to cover this missed scenario:
const generateCreateStubs = {
success: () => stub().resolves({ _id: USER_ID }),
genericError: () => stub().rejects(new Error()),
validationError: () => stub().rejects(new ValidationError(VALIDATION_ERROR_MESSAGE)),
};
...
describe('createUser', function () {
...
describe('When create rejects with an instance of Error', function () {
beforeEach(function () {
create = generateCreateStubs.genericError();
return createUser(req, res, db, create, validator, ValidationError);
});
describe('should call res.status()', function () {
it('once', function () {
assert(res.status.calledOnce);
});
it('with the argument 500', function () {
assert(res.status.calledWithExactly(500));
});
});
describe('should call res.set()', function () {
it('once', function () {
assert(res.set.calledOnce);
});
it('with the arguments "Content-Type" and "application/json"', function () {
assert(res.set.calledWithExactly('Content-Type', 'application/json'));
});
});
describe('should call res.json()', function () {
it('once', function () {
assert(res.json.calledOnce);
});
it('with a validation error object', function () {
assert(res.json.calledWithExactly({ message: 'Internal Server Error' }));
});
});
});
});
Now, when we run our test:unit:coverage script and look at the report again, you will be glad to see that coverage is now 100%!

Now, commit this refactoring step into your repository:
$ git add -A && git commit -m "Test catch block in createUser"