Mirror of https://github.com/roostorg/coop
github.com/roostorg/coop
1import {
2 CoopError,
3 ErrorType,
4 type ErrorInstanceData,
5} from '../../utils/errors.js';
6
7export type RuleErrorType =
8 | 'RuleNameExistsError'
9 | 'RuleHasRunningBacktestsError'
10 | 'RuleIsMissingContentTypeError';
11
12export const makeRuleNameExistsError = (data: ErrorInstanceData) =>
13 new CoopError({
14 status: 409,
15 type: [ErrorType.UniqueViolation],
16 title: 'A rule with that name already exists in this organization.',
17 name: 'RuleNameExistsError',
18 ...data,
19 });
20
21export const makeRuleIsMissingContentTypeError = (data: ErrorInstanceData) =>
22 new CoopError({
23 status: 400,
24 type: [ErrorType.InvalidUserInput],
25 title: 'This rule must contain a content type on which to operate.',
26 name: 'RuleIsMissingContentTypeError',
27 ...data,
28 });
29
30export const makeRuleHasRunningBacktestsError = (data: ErrorInstanceData) =>
31 new CoopError({
32 status: 409,
33 type: [ErrorType.AttemptingToMutateActiveRule],
34 title:
35 "This rule cannot be updated while it has running backtests, which are using the rule's current conditions.",
36 name: 'RuleHasRunningBacktestsError',
37 ...data,
38 });
39
40export type LocationBankErrorType = 'LocationBankNameExistsError';
41
42export const makeLocationBankNameExistsError = (data: ErrorInstanceData) =>
43 new CoopError({
44 status: 409,
45 type: [ErrorType.UniqueViolation],
46 title: 'A location bank with this name already exists',
47 name: 'LocationBankNameExistsError',
48 ...data,
49 });