I am currently learning and exploring new concepts, so please excuse any mistakes in my terminology or code :).
Here is the code snippet I have:
try {
if (!username ||
!password ||
!email ||
!firstname ||
!lastname ||
!phone_number||
!role) {
next({
name: "MissingCustomerDataError",
message: "Required Field - username, password, email, firstname, lastname, phone_number"
});
// throw new RouteError({
// name: "MissingCustomerDataError",
// message: "Required Field - username, password, email, firstname, lastname, phone_number"
// });
}
...(some more code)
const cust = await createCustomer({
username,
password,
email,
firstname,
lastname,
phone_number,
role,
address });
I expected that calling next(...) would exit this logic and trigger my error handler attached after this route. Unfortunately, it still calls the database function. Using throw does take me out of this logic and into the catch block. Shouldn't next also navigate out of this try block and move on? I believe there might be a conceptual misunderstanding on my end. Thanks for your help!