1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Add db-error code file

This commit is contained in:
Christopher Kolstad 2021-02-09 10:19:35 +01:00
parent 063d3f0e4a
commit d1d271bb41
No known key found for this signature in database
GPG Key ID: 559ACB0E3DB5538A
2 changed files with 5 additions and 1 deletions

View File

@ -4,6 +4,7 @@ const metricsHelper = require('../metrics-helper');
const { DB_TIME } = require('../events'); const { DB_TIME } = require('../events');
const NotFoundError = require('../error/notfound-error'); const NotFoundError = require('../error/notfound-error');
const FeatureHasTagError = require('../error/feature-has-tag-error'); const FeatureHasTagError = require('../error/feature-has-tag-error');
const { UNIQUE_CONSTRAINT_VIOLATION } = require('../error/db-error');
const FEATURE_COLUMNS = [ const FEATURE_COLUMNS = [
'name', 'name',
@ -242,7 +243,7 @@ class FeatureToggleStore {
await this.db(FEATURE_TAG_TABLE) await this.db(FEATURE_TAG_TABLE)
.insert(this.featureAndTagToRow(featureName, tag)) .insert(this.featureAndTagToRow(featureName, tag))
.catch(err => { .catch(err => {
if (err.code === '23505') { if (err.code === UNIQUE_CONSTRAINT_VIOLATION) {
throw new FeatureHasTagError( throw new FeatureHasTagError(
`${featureName} already had the tag: [${tag.type}:${tag.value}]`, `${featureName} already had the tag: [${tag.type}:${tag.value}]`,
); );

3
lib/error/db-error.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
UNIQUE_CONSTRAINT_VIOLATION: '23505',
};