Skip to content

Commit c440916

Browse files
committed
add unknown op error
1 parent f112aac commit c440916

File tree

8 files changed

+21
-27
lines changed

8 files changed

+21
-27
lines changed

src/core/executors/CustomEventOperationExecutor.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
getDeviceOS,
44
getSubscriptionType,
55
} from 'src/shared/environment/detect';
6+
import { UnknownOpError } from 'src/shared/errors/common';
67
import {
78
getResponseStatusType,
89
ResponseStatusType,
@@ -44,9 +45,7 @@ export class CustomEventsOperationExecutor implements IOperationExecutor {
4445
const operation = operations[0];
4546

4647
if (!(operation instanceof TrackCustomEventOperation)) {
47-
throw new Error(
48-
`Unrecognized operation! Expected TrackEventOperation, got: ${operation.constructor.name}`,
49-
);
48+
throw UnknownOpError(operation);
5049
}
5150

5251
const response = await sendCustomEvent(

src/core/executors/IdentityOperationExecutor.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type IOperationExecutor,
55
} from 'src/core/types/operation';
66
import type { IRebuildUserService } from 'src/core/types/user';
7+
import { UnknownOpError } from 'src/shared/errors/common';
78
import {
89
getResponseStatusType,
910
ResponseStatusType,
@@ -40,9 +41,7 @@ export class IdentityOperationExecutor implements IOperationExecutor {
4041
}
4142

4243
async _execute(operations: Operation[]): Promise<ExecutionResponse> {
43-
debug(
44-
`IdentityOperationExecutor(operations: ${JSON.stringify(operations)})`,
45-
);
44+
debug(`IdentityOperationExecutor`);
4645

4746
const invalidOps = operations.filter(
4847
(op) =>
@@ -51,11 +50,7 @@ export class IdentityOperationExecutor implements IOperationExecutor {
5150
),
5251
);
5352
if (invalidOps.length > 0) {
54-
throw new Error(
55-
`Unrecognized operation(s)! Attempted operations:\n${JSON.stringify(
56-
operations,
57-
)}`,
58-
);
53+
throw UnknownOpError(operations);
5954
}
6055

6156
const hasSetAlias = operations.some(

src/core/executors/LoginUserOperationExecutor.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
ExecutionResult,
44
type IOperationExecutor,
55
} from 'src/core/types/operation';
6+
import { UnknownOpError } from 'src/shared/errors/common';
67
import { getTimeZoneId } from 'src/shared/helpers/general';
78
import {
89
getResponseStatusType,
@@ -62,15 +63,13 @@ export class LoginUserOperationExecutor implements IOperationExecutor {
6263
}
6364

6465
async _execute(operations: Operation[]): Promise<ExecutionResponse> {
65-
debug(
66-
`LoginUserOperationExecutor(operation: ${JSON.stringify(operations)})`,
67-
);
66+
debug(`LoginUserOperationExecutor`);
6867
const startingOp = operations[0];
6968

7069
if (startingOp instanceof LoginUserOperation)
7170
return this._loginUser(startingOp, operations.slice(1));
7271

73-
throw new Error(`Unrecognized operation: ${startingOp._name}`);
72+
throw UnknownOpError(startingOp);
7473
}
7574

7675
private async _loginUser(
@@ -163,7 +162,7 @@ export class LoginUserOperationExecutor implements IOperationExecutor {
163162
subscriptions,
164163
);
165164
} else {
166-
throw new Error(`Unrecognized operation: ${operation._name}`);
165+
throw UnknownOpError(operation);
167166
}
168167
}
169168

src/core/executors/RefreshUserOperationExecutor.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UnknownOpError } from 'src/shared/errors/common';
12
import {
23
getResponseStatusType,
34
ResponseStatusType,
@@ -52,16 +53,10 @@ export class RefreshUserOperationExecutor implements IOperationExecutor {
5253
}
5354

5455
async _execute(operations: Operation[]): Promise<ExecutionResponse> {
55-
debug(
56-
`RefreshUserOperationExecutor(operation: ${JSON.stringify(operations)})`,
57-
);
56+
debug(`RefreshUserOperationExecutor`);
5857

5958
if (operations.some((op) => !(op instanceof RefreshUserOperation)))
60-
throw new Error(
61-
`Unrecognized operation(s)! Attempted operations:\n${JSON.stringify(
62-
operations,
63-
)}`,
64-
);
59+
throw UnknownOpError(operations);
6560

6661
const startingOp = operations[0];
6762
return this._getUser(startingOp);

src/core/executors/SubscriptionOperationExecutor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type IOperationExecutor,
44
} from 'src/core/types/operation';
55
import type { IRebuildUserService } from 'src/core/types/user';
6+
import { UnknownOpError } from 'src/shared/errors/common';
67
import {
78
getResponseStatusType,
89
ResponseStatusType,
@@ -79,7 +80,7 @@ export class SubscriptionOperationExecutor implements IOperationExecutor {
7980
);
8081
return this._transferSubscription(startingOp);
8182
}
82-
throw new Error(`Unrecognized operation: ${startingOp}`);
83+
throw UnknownOpError(startingOp);
8384
}
8485

8586
private async _createSubscription(

src/core/executors/UpdateUserOperationExecutor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UnknownOpError } from 'src/shared/errors/common';
12
import {
23
getResponseStatusType,
34
ResponseStatusType,
@@ -65,7 +66,7 @@ export class UpdateUserOperationExecutor implements IOperationExecutor {
6566
propertiesObject,
6667
);
6768
} else {
68-
throw new Error(`Unrecognized operation: ${operation}`);
69+
throw UnknownOpError(operation);
6970
}
7071
}
7172

src/core/modelRepo/OperationModelStore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { IDBStoreName } from 'src/shared/database/types';
2+
import { UnknownOpError } from 'src/shared/errors/common';
23
import { error } from 'src/shared/libraries/log';
34
import { OPERATION_NAME } from '../constants';
45
import { CreateSubscriptionOperation } from '../operations/CreateSubscriptionOperation';
@@ -71,7 +72,7 @@ export class OperationModelStore extends ModelStore<Operation> {
7172
operation = new TrackCustomEventOperation();
7273
break;
7374
default:
74-
throw new Error(`Unrecognized operation: ${operationName}`);
75+
throw UnknownOpError({ _name: operationName });
7576
}
7677

7778
// populate the operation with the data

src/shared/errors/common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@ export const WrongTypeArgumentError = (argName: string) =>
6565

6666
export const ReservedArgumentError = (argName: string) =>
6767
new Error(`"${argName}" is reserved`);
68+
69+
export const UnknownOpError = (op: { _name?: string } | { _name?: string }[]) =>
70+
new Error(`Unknown op(s):${op}`);

0 commit comments

Comments
 (0)