@vorplex/api 0.0.55 → 0.0.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $Array, $Router, $String, $Tson, Emitter, Injector, MimeType, Task,
|
|
1
|
+
import { $Array, $Router, $String, $Tson, Emitter, Injector, MimeType, Task, WebClient } from '@vorplex/core';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import { Server as NodeHttpServer } from 'http';
|
|
4
4
|
import { Server as NodeHttpsServer } from 'https';
|
|
@@ -217,23 +217,18 @@ export class Server {
|
|
|
217
217
|
}
|
|
218
218
|
});
|
|
219
219
|
const schema = $Tson.parse(definition);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
schema
|
|
233
|
-
});
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
throw error;
|
|
220
|
+
const [parsedPacket, packetErrors] = schema.parse(packet);
|
|
221
|
+
if (packetErrors.length > 0) {
|
|
222
|
+
const [parseError] = packetErrors;
|
|
223
|
+
client.send({
|
|
224
|
+
error: {
|
|
225
|
+
message: parseError.message,
|
|
226
|
+
path: parseError.path,
|
|
227
|
+
schema: parseError.schema
|
|
228
|
+
},
|
|
229
|
+
schema
|
|
230
|
+
});
|
|
231
|
+
return;
|
|
237
232
|
}
|
|
238
233
|
const task = new Task(`[${parsedPacket.id}] Packet`);
|
|
239
234
|
try {
|
|
@@ -246,21 +241,17 @@ export class Server {
|
|
|
246
241
|
});
|
|
247
242
|
let data = parsedPacket.data;
|
|
248
243
|
if (action.schema) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
value: error.value
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
else
|
|
262
|
-
throw error;
|
|
244
|
+
const [parsedData, dataErrors] = $Tson.parse(action.schema).parse(parsedPacket.data);
|
|
245
|
+
if (dataErrors.length > 0) {
|
|
246
|
+
const [dataError] = dataErrors;
|
|
247
|
+
throw new WebError(`Failed to parse packet data for hub (${hub.name}) with action (${action.name})`, {
|
|
248
|
+
message: dataError.message,
|
|
249
|
+
path: dataError.path,
|
|
250
|
+
schema: dataError.schema,
|
|
251
|
+
value: dataError.value
|
|
252
|
+
});
|
|
263
253
|
}
|
|
254
|
+
data = parsedData;
|
|
264
255
|
}
|
|
265
256
|
await action.callback({
|
|
266
257
|
injector: this.injector,
|