Skip to main content

Function: isDuplicateKeyError()

isDuplicateKeyError(err): boolean

Defined in: service-core/src/database/DatabaseErrors.ts:24

Determines whether err is a unique/primary key violation reported by any of the supported database drivers:

  • MongoDB: code 11000 (or 11001);
  • PostgreSQL: SQLSTATE 23505;
  • MySQL/MariaDB: ER_DUP_ENTRY (errno 1062);
  • SQLite (better-sqlite3/sqlite3): SQLITE_CONSTRAINT_UNIQUE/SQLITE_CONSTRAINT_PRIMARYKEY, or a generic SQLITE_CONSTRAINT whose message is a UNIQUE constraint failed error.

Parameters​

err​

any

The error to inspect.

Returns​

boolean