title: node js function connect to postgres return error
body: <p>I have this function. It works great when the query is successful but when I get an error I need to return an error response. I have seen a few examples using res.json but res in not available in the catch . How can I return an error response to the user of this api.</p>
  <pre><code>     pg.Client = config;
              client = await pool.connect();
              pool.connect()
              .then(client =&gt; {
                  return client.query(query)
                      .then(res =&gt; {
                          client.release();
                          return res.rows;
                      })
                      .catch(e =&gt; {
                          client.release();
                          console.log(e.stack);
                      })
            }).finally(() =&gt; client.close);
  
  </code></pre>