Skip to content

Commit ead0f23

Browse files
committed
Explicitly reject unrecognized rule types during loading
Previously this reported a generic undefined error when trying to load a rule export with an unrecognized rule - it now fails explicitly complaining about the unrecognized type in question.
1 parent 5f55fba commit ead0f23

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/model/rules/rule-serialization.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ const deserializeByType = <T extends { type: string, uiType?: string }>(
2626
) => {
2727
// uiType allows us to override deserialization for UI representations only,
2828
// but keep the same serialization type for real Mockttp rules.
29-
const clazz = lookup[data.uiType || data.type];
29+
const typeKey = data.uiType || data.type;
30+
const clazz = lookup[typeKey];
31+
32+
if (!clazz) throw new Error(`Can't load unrecognized rule type: ${typeKey}`);
3033

3134
if (hasSerializrSchema(clazz)) {
3235
return serializr.deserialize(clazz, data, () => {}, args);

0 commit comments

Comments
 (0)