@athenna/database
Version:
The Athenna database handler for SQL/NoSQL.
27 lines (26 loc) • 1.14 kB
JavaScript
/**
* @athenna/database
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { ConstraintViolationException } from '#src/exceptions/ConstraintViolationException';
export class UniqueViolationException extends ConstraintViolationException {
constructor(meta = {}) {
const { table, columns, constraint, driver, raw } = meta;
const cols = columns?.length ? columns.join(', ') : null;
super({
status: 409,
code: 'E_UNIQUE_VIOLATION',
message: `Unique constraint${constraint ? ` "${constraint}"` : ''} violated${table ? ` on table "${table}"` : ''}${cols ? ` for column(s) [${cols}]` : ''}.`,
help: `A record with the same ${cols ?? 'unique value'} already exists. Use createOrIgnore()/createOrFirst() to handle the conflict gracefully, or persist a different value.`
});
this.table = table;
this.columns = columns;
this.constraint = constraint;
this.driver = driver;
this.raw = raw;
}
}