diff --git a/lib/misc/errors.js b/lib/misc/errors.js index 025f4bab..f12dbfee 100644 --- a/lib/misc/errors.js +++ b/lib/misc/errors.js @@ -13,7 +13,7 @@ class SqlError extends Error { (sql ? '\nsql: ' + sql : '') ); this.name = 'SqlError'; - this.text = msg; + this.sqlMessage = msg; this.sql = sql; this.fatal = fatal; this.errno = errno; @@ -29,6 +29,10 @@ class SqlError extends Error { this.stack += '\n From event:\n' + additionalStack.substring(additionalStack.indexOf('\n') + 1); } } + + get text() { + return this.sqlMessage; + } } /** diff --git a/test/integration/test-error.js b/test/integration/test-error.js index b6e63dbc..52aa6033 100644 --- a/test/integration/test-error.js +++ b/test/integration/test-error.js @@ -41,6 +41,7 @@ describe('Error', () => { assert.equal(err.sqlState, 42000); assert.isTrue(err.message.includes('You have an error in your SQL syntax')); assert.isTrue(err.message.includes('sql: wrong query - parameters:[]')); + assert.isTrue(err.sqlMessage.includes('You have an error in your SQL syntax')); } } conn.end(); diff --git a/types/index.d.ts b/types/index.d.ts index c45fe76c..42ace3b1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -852,9 +852,15 @@ export interface SqlError extends Error { /** * original error message value + * @deprecated since 3.2.0 prefer using sqlMessage for compatibility with other drivers. */ text: string | null; + /** + * original error message value + */ + sqlMessage: string | null; + /** * The sql command associate */