MCPcopy Index your code
hub / github.com/sequelize/sequelize / formatError

Method formatError

src/dialects/oracle/query.js:533–598  ·  view source on GitHub ↗
(err)

Source from the content-addressed store, hash-verified

531 }
532
533 formatError(err) {
534 let match;
535 // ORA-00001: unique constraint (USER.XXXXXXX) violated
536 match = err.message.match(/unique constraint ([\s\S]*) violated/);
537 if (match && match.length > 1) {
538 match[1] = match[1].replace('(', '').replace(')', '').split('.')[1]; // As we get (SEQUELIZE.UNIQNAME), we replace to have UNIQNAME
539 const errors = [];
540 let fields = [],
541 message = 'Validation error',
542 uniqueKey = null;
543
544 if (this.model) {
545 const uniqueKeys = Object.keys(this.model.uniqueKeys);
546
547 const currKey = uniqueKeys.find(key => {
548 // We check directly AND with quotes -> "a"" === a || "a" === "a"
549 return key.toUpperCase() === match[1].toUpperCase() || key.toUpperCase() === `"${match[1].toUpperCase()}"`;
550 });
551
552 if (currKey) {
553 uniqueKey = this.model.uniqueKeys[currKey];
554 fields = uniqueKey.fields;
555 }
556
557 if (uniqueKey && !!uniqueKey.msg) {
558 message = uniqueKey.msg;
559 }
560
561 fields.forEach(field => {
562 errors.push(
563 new SequelizeErrors.ValidationErrorItem(
564 this.getUniqueConstraintErrorMessage(field),
565 'unique violation',
566 field,
567 null
568 )
569 );
570 });
571 }
572
573 return new SequelizeErrors.UniqueConstraintError({
574 message,
575 errors,
576 err,
577 fields
578 });
579 }
580
581 // ORA-02291: integrity constraint (string.string) violated - parent key not found / ORA-02292: integrity constraint (string.string) violated - child record found
582 match = err.message.match(/ORA-02291/) || err.message.match(/ORA-02292/);
583 if (match && match.length > 0) {
584 return new SequelizeErrors.ForeignKeyConstraintError({
585 fields: null,
586 index: match[1],
587 parent: err
588 });
589 }
590

Callers 1

runMethod · 0.95

Calls 1

Tested by

no test coverage detected