brianc / node-pg-types

Type parsing for node-postgres
268 stars 55 forks source link

Error message undefined #74

Closed houssemDevs closed 5 years ago

houssemDevs commented 5 years ago

Hi,

I am using pg to execute a stored procedure on postegres 10, this procedure may fail and raise an exception, the exception message can not be extracted from the error (err.error 'undefined'), but can be logged on the console. when I log the error (console.log(err);) I see the exception message along with the stack trace, but when I log only the error message (console.log(err.error)) I get undefined.

let query = {
    text: 'SELECT insert_events($1, $2, $3, $4, $5)',
    values: [provider, type, events, types, expectedVersion],
  };
  const qfunc = async () => {
    const cnn = await pool.connect();
    try {
      const res = await cnn.query(query);
      return res.rows[0].insert_events;
    } catch (err) {
      console.log('Error : ', err.where);
      throw err;
    } finally {
      cnn.release();
    }
  };
  return qfunc();
charmander commented 5 years ago

The property for the message associated with an Error object in JavaScript is err.message, not err.error.

houssemDevs commented 5 years ago

I did say err.error because of this : Imgur

charmander commented 5 years ago

The word “error:” there is part of the error message. It’s not a property.

houssemDevs commented 5 years ago

I am not sure but when I use err.message as you suggested I get the message "Concurrency problem ...... ". But the issue is solved thank you.

houssemDevs commented 5 years ago

I will close the issue. Thank you for your help.