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

Commit 3a74da81 by Mick Hansen

Merge pull request #2395 from vpontis/error-parsing

add different error format for 23505 error on postgres
2 parents 60ab9024 bc9904f7
Showing with 18 additions and 9 deletions
......@@ -256,15 +256,24 @@ module.exports = (function() {
parent: err
});
case '23505':
match = err.detail.match(/Key \((.*?)\)=\((.*?)\) already exists/);
return new sequelizeErrors.UniqueConstraintError({
fields: match[1].split(', '),
value: match[2].split(', '),
index: null,
parent: err
});
// there are multiple different formats of error messages for this error code
// this regex should check at least two
match = err.detail.match(/Key \((.*?)\)=\((.*?)\)/);
if (match) {
return new sequelizeErrors.UniqueConstraintError({
fields: match[1].split(', '),
value: match[2].split(', '),
index: null,
parent: err
});
} else {
return new sequelizeErrors.UniqueConstraintError({
error: err,
message: err.message
});
}
break;
default:
return new sequelizeErrors.DatabaseError(err);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!