Fix error schema

This commit is contained in:
Aleksandr Kraiz
2023-03-15 14:33:24 +04:00
parent 6c16403048
commit 0c298fcd76
4 changed files with 38 additions and 10 deletions

View File

@@ -370,13 +370,15 @@ class OrionAggregatorWS {
// Get subscription error callback
// 2. Find subscription by id
// 3. Call onError callback
const subType = objectKeys(this.subscriptions).find((st) => this.subscriptions[st]?.[err.id]);
if (subType === undefined) throw new Error('OrionAggregatorWS: cannot find subscription type by id');
const sub = this.subscriptions[subType]?.[err.id];
if (sub === undefined) throw new Error('OrionAggregatorWS: cannot find subscription by id');
if ('errorCb' in sub) {
sub.errorCb(err.m);
const { id } = err;
if (id !== undefined) {
const subType = objectKeys(this.subscriptions).find((st) => this.subscriptions[st]?.[id]);
if (subType === undefined) throw new Error('OrionAggregatorWS: cannot find subscription type by id');
const sub = this.subscriptions[subType]?.[id];
if (sub === undefined) throw new Error('OrionAggregatorWS: cannot find subscription by id');
if ('errorCb' in sub) {
sub.errorCb(err.m);
}
}
this.onError?.(err.m);
}

View File

@@ -5,7 +5,7 @@ import baseMessageSchema from './baseMessageSchema';
const errorSchema = baseMessageSchema.extend({
T: z.literal(MessageType.ERROR),
c: z.number().int(), // code
id: z.string(), // subscription id
id: z.string().optional(), // subscription id
m: z.string(), // error message,
});