Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 218f8cd2
authored
Aug 22, 2019
by
Roman UNTILOV
Committed by
Sushant
Aug 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(database-error): add parameters property (#11343)
1 parent
1bf032dd
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
22 additions
and
0 deletions
lib/dialects/mariadb/query.js
lib/dialects/mssql/query.js
lib/dialects/mysql/query.js
lib/dialects/postgres/query.js
lib/errors/database-error.js
test/integration/error.test.js
types/lib/errors.d.ts
lib/dialects/mariadb/query.js
View file @
218f8cd
...
@@ -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
);
})
})
)
)
...
...
lib/dialects/mssql/query.js
View file @
218f8cd
...
@@ -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
));
...
...
lib/dialects/mysql/query.js
View file @
218f8cd
...
@@ -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
{
...
...
lib/dialects/postgres/query.js
View file @
218f8cd
...
@@ -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
=>
{
...
...
lib/errors/database-error.js
View file @
218f8cd
...
@@ -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
);
}
}
}
}
...
...
test/integration/error.test.js
View file @
218f8cd
...
@@ -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
);
...
...
types/lib/errors.d.ts
View file @
218f8cd
...
@@ -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
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment