mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
create custom error for release actions
This commit is contained in:
parent
9403426835
commit
3523c1f7cf
@ -14,6 +14,7 @@ import type {
|
||||
} from '../../../shared/contracts/release-actions';
|
||||
import { getService } from '../utils';
|
||||
import { RELEASE_ACTION_MODEL_UID } from '../constants';
|
||||
import { AlreadyOnReleaseError } from '../services/validation';
|
||||
|
||||
const releaseActionController = {
|
||||
async create(ctx: Koa.Context) {
|
||||
@ -48,11 +49,8 @@ const releaseActionController = {
|
||||
|
||||
return action;
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof errors.ValidationError &&
|
||||
error.message ===
|
||||
`Entry with id ${releaseActionArgs.entry.id} and contentType ${releaseActionArgs.entry.contentType} already exists in release with id ${releaseId}`
|
||||
) {
|
||||
// If the entry is already in the release, we don't want to throw an error, so we catch and ignore it
|
||||
if (error instanceof AlreadyOnReleaseError) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,13 @@ import type { Release, CreateRelease, UpdateRelease } from '../../../shared/cont
|
||||
import type { CreateReleaseAction } from '../../../shared/contracts/release-actions';
|
||||
import { RELEASE_MODEL_UID } from '../constants';
|
||||
|
||||
export class AlreadyOnReleaseError extends errors.ApplicationError<'AlreadyOnReleaseError'> {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'AlreadyOnReleaseError';
|
||||
}
|
||||
}
|
||||
|
||||
const createReleaseValidationService = ({ strapi }: { strapi: LoadedStrapi }) => ({
|
||||
async validateUniqueEntry(
|
||||
releaseId: CreateReleaseAction.Request['params']['releaseId'],
|
||||
@ -29,7 +36,7 @@ const createReleaseValidationService = ({ strapi }: { strapi: LoadedStrapi }) =>
|
||||
);
|
||||
|
||||
if (isEntryInRelease) {
|
||||
throw new errors.ValidationError(
|
||||
throw new AlreadyOnReleaseError(
|
||||
`Entry with id ${releaseActionArgs.entry.id} and contentType ${releaseActionArgs.entry.contentType} already exists in release with id ${releaseId}`
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user