mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-24 22:58:01 +03:00
Fix error schema
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.17.35",
|
||||
"version": "0.17.36",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/esm/index.js",
|
||||
"module": "./lib/esm/index.js",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Orion from '../Orion';
|
||||
|
||||
describe('Orion Aggregator', () => {
|
||||
test('Handle error', async () => {
|
||||
test('Handle error aus', async () => {
|
||||
const orion = new Orion('testing');
|
||||
const bscUnit = orion.getUnit('bsc')
|
||||
|
||||
@@ -27,4 +27,30 @@ describe('Orion Aggregator', () => {
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
test('Handle error aobus', async () => {
|
||||
const orion = new Orion('testing');
|
||||
const bscUnit = orion.getUnit('bsc')
|
||||
|
||||
let subId: string;
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
bscUnit.orionAggregator.ws.unsubscribe(subId);
|
||||
bscUnit.orionAggregator.ws.destroy()
|
||||
reject(new Error('Timeout'));
|
||||
}, 10000);
|
||||
const payload = 'BTCUSDF';
|
||||
subId = bscUnit.orionAggregator.ws.subscribe('aobus', {
|
||||
payload,
|
||||
callback: () => null,
|
||||
errorCb: (message) => {
|
||||
console.log(message);
|
||||
clearTimeout(timeout);
|
||||
bscUnit.orionAggregator.ws.destroy()
|
||||
resolve(true);
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user