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

Commit cece97a1 by Rui Marinho

Update error format for postgresql

`node-libpq` now exposes more detailed error information.
1 parent a1a1400e
Showing with 9 additions and 5 deletions
......@@ -256,10 +256,14 @@ module.exports = (function() {
, table
, index;
switch (err.code) {
var code = err.code || err.sqlState
, errMessage = err.message || err.messagePrimary
, errDetail = err.detail || err.messageDetail;
switch (code) {
case '23503':
index = err.message.match(/violates foreign key constraint \"(.+?)\"/)[1];
table = err.message.match(/on table \"(.+?)\"/)[1];
index = errMessage.match(/violates foreign key constraint \"(.+?)\"/)[1];
table = errMessage.match(/on table \"(.+?)\"/)[1];
return new sequelizeErrors.ForeignKeyConstraintError({
fields: null,
......@@ -270,7 +274,7 @@ module.exports = (function() {
case '23505':
// there are multiple different formats of error messages for this error code
// this regex should check at least two
match = err.detail.match(/Key \((.*?)\)=\((.*?)\)/);
match = errDetail.match(/Key \((.*?)\)=\((.*?)\)/);
if (match) {
var fields = Utils._.zipObject(match[1].split(', '), match[2].split(', '))
......@@ -299,7 +303,7 @@ module.exports = (function() {
});
} else {
return new sequelizeErrors.UniqueConstraintError({
message: err.message,
message: errMessage,
parent: err
});
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!