diff --git a/packages/server/src/error/ErrorTransformer.ts b/packages/server/src/error/ErrorTransformer.ts index 289867e..cb9e0b1 100644 --- a/packages/server/src/error/ErrorTransformer.ts +++ b/packages/server/src/error/ErrorTransformer.ts @@ -20,6 +20,12 @@ export class ErrorTransformer { } return match === err.message } + + throwIfNotMatch(err: Error) { + if (!this.isMatch(err)) { + throw err + } + } } export const UniqueTransformer = new ErrorTransformer(400, /unique/i) diff --git a/packages/server/src/story/StoryService.ts b/packages/server/src/story/StoryService.ts index 5185f34..2db7d15 100644 --- a/packages/server/src/story/StoryService.ts +++ b/packages/server/src/story/StoryService.ts @@ -4,6 +4,7 @@ import {ISiteService} from '../site/ISiteService' import {IStoryService} from './IStoryService' import {ITransactionManager} from '../database/ITransactionManager' import {Story} from '../entities/Story' +import {UniqueTransformer} from '../error/ErrorTransformer' export class StoryService extends BaseService implements IStoryService { constructor( @@ -35,7 +36,8 @@ export class StoryService extends BaseService implements IStoryService { siteId: site.id, }) } catch (err) { - // TODO check if unique constrint error + // throw if not a unique constraint error + UniqueTransformer.throwIfNotMatch(err) // This could happen if there are two concurrent requests coming in at // the same time, and they both cannot find the story, then decide to