不要怂,就是干,撸起袖子干!

Commit 218f8cd2 by Roman UNTILOV Committed by Sushant

feat(database-error): add parameters property (#11343)

1 parent 1bf032dd
...@@ -64,6 +64,7 @@ class Query extends AbstractQuery { ...@@ -64,6 +64,7 @@ class Query extends AbstractQuery {
complete(); complete();
err.sql = sql; err.sql = sql;
err.parameters = parameters;
throw this.formatError(err); throw this.formatError(err);
}) })
) )
......
...@@ -70,6 +70,7 @@ class Query extends AbstractQuery { ...@@ -70,6 +70,7 @@ class Query extends AbstractQuery {
if (err) { if (err) {
err.sql = sql; err.sql = sql;
err.parameters = parameters;
reject(this.formatError(err)); reject(this.formatError(err));
} else { } else {
resolve(this.formatResults(results, rowCount)); resolve(this.formatResults(results, rowCount));
......
...@@ -46,6 +46,7 @@ class Query extends AbstractQuery { ...@@ -46,6 +46,7 @@ class Query extends AbstractQuery {
options.transaction.finished = 'rollback'; options.transaction.finished = 'rollback';
} }
err.sql = sql; err.sql = sql;
err.parameters = parameters;
reject(this.formatError(err)); reject(this.formatError(err));
} else { } else {
......
...@@ -68,6 +68,7 @@ class Query extends AbstractQuery { ...@@ -68,6 +68,7 @@ class Query extends AbstractQuery {
} }
err.sql = sql; err.sql = sql;
err.parameters = parameters;
throw this.formatError(err); throw this.formatError(err);
}) })
.then(queryResult => { .then(queryResult => {
......
...@@ -22,6 +22,11 @@ class DatabaseError extends BaseError { ...@@ -22,6 +22,11 @@ class DatabaseError extends BaseError {
* @type {string} * @type {string}
*/ */
this.sql = parent.sql; this.sql = parent.sql;
/**
* The parameters for the sql that triggered the error
* @type {Array<any>}
*/
this.parameters = parent.parameters;
Error.captureStackTrace(this, this.constructor); Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -171,6 +171,18 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => { ...@@ -171,6 +171,18 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => {
expect(databaseError.message).to.equal('original database error message'); expect(databaseError.message).to.equal('original database error message');
}); });
it('SequelizeDatabaseError should keep the original sql and the parameters', () => {
const orig = new Error();
orig.sql = 'SELECT * FROM table WHERE id = $1';
orig.parameters = ['1'];
const databaseError = new Sequelize.DatabaseError(orig);
expect(databaseError).to.have.property('sql');
expect(databaseError).to.have.property('parameters');
expect(databaseError.sql).to.equal(orig.sql);
expect(databaseError.parameters).to.equal(orig.parameters);
});
it('ConnectionError should keep original message', () => { it('ConnectionError should keep original message', () => {
const orig = new Error('original connection error message'); const orig = new Error('original connection error message');
const connectionError = new Sequelize.ConnectionError(orig); const connectionError = new Sequelize.ConnectionError(orig);
......
...@@ -79,6 +79,7 @@ export class DatabaseError extends BaseError implements CommonErrorProperties { ...@@ -79,6 +79,7 @@ export class DatabaseError extends BaseError implements CommonErrorProperties {
public readonly parent: Error; public readonly parent: Error;
public readonly original: Error; public readonly original: Error;
public readonly sql: string; public readonly sql: string;
public readonly parameters: Array<any>;
/** /**
* A base class for all database related errors. * A base class for all database related errors.
* @param parent The database specific error which triggered this one * @param parent The database specific error which triggered this one
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!