title: why does this mysql error causes nodejs to crash instead of going to the catch function?
body: <p>I have a mysql statement that creates an entry, it has a <code>.then</code> function and a <code>.catch</code> function, but when the following error occurs:</p>
  
  <p><code>TypeError('Bind parameters must not contain undefined. To pass SQL NULL specify JS null');</code></p>
  
  <p>the server crashes instead of answering a 500 like defined in the <code>.catch</code> function</p>
  
  <p>Note: I'm using the <code>mysql2</code> library from npm with promises (<code>require('mysql2/promise');</code>)</p>
  
  <p>Here's the code that calls it (<code>req.params.account_name</code> is <code>undefined</code>):</p>
  
  <pre><code>const CREATE_ACCOUNT_STATEMENT =
    'INSERT INTO `Accounts` (`account_token`, `account_name`) VALUES (?, ?)'
  
  try {
    mysqlConnectionPool.execute(CREATE_ACCOUNT_STATEMENT, [
      account_token, account_name
    ])
    .then(() =&gt; {
      res.end(JSON.stringify({ token: account_token }))
    })
    .catch((e) =&gt; {
      debug(1, "error while trying to create account:", e)
      res.status(500).end("Internal Server Error")
    })
  } catch(e) {
    debug(1, "error while trying to create account:", e)
    res.status(500).end("Internal Server Error")
  }
  </code></pre>