Add db-error code file

This commit is contained in:
Christopher Kolstad
2021-02-09 10:19:35 +01:00
parent 063d3f0e4a
commit d1d271bb41
2 changed files with 5 additions and 1 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ const metricsHelper = require('../metrics-helper');
const { DB_TIME } = require('../events');
const NotFoundError = require('../error/notfound-error');
const FeatureHasTagError = require('../error/feature-has-tag-error');
const { UNIQUE_CONSTRAINT_VIOLATION } = require('../error/db-error');
const FEATURE_COLUMNS = [
'name',
@@ -242,7 +243,7 @@ class FeatureToggleStore {
await this.db(FEATURE_TAG_TABLE)
.insert(this.featureAndTagToRow(featureName, tag))
.catch(err => {
if (err.code === '23505') {
if (err.code === UNIQUE_CONSTRAINT_VIOLATION) {
throw new FeatureHasTagError(
`${featureName} already had the tag: [${tag.type}:${tag.value}]`,
);
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
UNIQUE_CONSTRAINT_VIOLATION: '23505',
};