Add unique constraint check to StoryService
This commit is contained in:
parent
a4be36d159
commit
406858cf2d
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user