Right now, the server crashes if you sign up using duplicate email

How can you fix this?

Approach #1 - Try catch

In JavaScript, a try...catch block is used for handling exceptions and errors that occur during the execution of code. It allows you to write code that can manage errors gracefully rather than crashing the application or causing unexpected behavior.

try {
  // Attempt to execute this code
  let result = riskyFunction(); // This function might throw an error
  console.log('Result:', result);
} catch (error) {
  // Handle the error if one is thrown
  console.error('An error occurred:', error.message);
} finally {
  // This block will always execute
  console.log('Cleanup code or final steps.');
}