// Rounds a number to ˋplacesˋ amount of digits
// Example roundOff(5.2434234234, 3) => 5.243
let roundOff = (num, places) => {
  const x = Math.pow(10, places);
  return Math.round(num * x) / x;
};

function handleMysqlErrors(err, title) {
  if (err) {
    if (err.code == "ECONNREFUSED") {
      console.log(
        "⚠ Connection to database failed. Is the database server running? ⚠"
      );
      process.exit(5);
    } else if (err.code == "ECONNRESET") {
      console.log("⚠ Module " + title + " experienced a connection reset ⚠");
      process.exit(5);
    } else {
      console.warn("!!!!!!!!!!!!!!!! NOW THROWING " + err.code + " !!!!!!!!!!!!!!!!")
      throw err;
    }
  }
}

module.exports = { roundOff, handleMysqlErrors };
