systemlynx 1.10.6 → 1.10.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systemlynx",
3
- "version": "1.10.6",
3
+ "version": "1.10.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,21 +32,27 @@ module.exports = function createClient(httpClient = HttpClient(), systemContext)
32
32
  Client.cachedServices[connData.serviceUrl] = Service;
33
33
 
34
34
  Service.resetConnection = async (cb) => {
35
- const { modules, host, port, namespace } = await loadConnectionData(
36
- httpClient,
37
- connData.serviceUrl
38
- );
39
- SocketDispatcher.apply(Service, [namespace, events, systemContext]);
35
+ try {
36
+ const { modules, host, port, namespace } = await loadConnectionData(
37
+ httpClient,
38
+ connData.serviceUrl
39
+ );
40
+ SocketDispatcher.apply(Service, [namespace, events, systemContext]);
40
41
 
41
- modules.forEach(({ namespace, route, name }) => {
42
- if (Service[name]) {
43
- Service[name].__setConnection(host, port, route, namespace);
44
- Service[name].emit("reconnect");
45
- }
46
- });
42
+ modules.forEach(({ namespace, route, name }) => {
43
+ if (Service[name]) {
44
+ Service[name].__setConnection(host, port, route, namespace);
45
+ Service[name].emit("reconnect");
46
+ }
47
+ });
47
48
 
48
- Service.emit("reconnect");
49
- if (typeof cb === "function") cb();
49
+ Service.emit("reconnect");
50
+ if (typeof cb === "function") cb();
51
+ } catch (error) {
52
+ console.error(
53
+ `[SystemLynx][Client]: Failed to reconnect service @${connData.serviceUrl}`
54
+ );
55
+ }
50
56
  };
51
57
 
52
58
  connData.modules.forEach(
@@ -22,12 +22,19 @@ module.exports = function SystemLynxClientModule(
22
22
  ClientModule.__setConnection(host, port, route, namespace);
23
23
 
24
24
  const reconnectModule = async (cb) => {
25
- const url = connectionData.serviceUrl + `?modules=${name}`;
25
+ try {
26
+ const url = connectionData.serviceUrl + `?modules=${name}`;
26
27
  const { modules, port, host } = await loadConnectionData(url);
27
28
  const { namespace, route } = modules[0];
28
29
  ClientModule.__setConnection(host, port, route, namespace);
29
30
 
30
31
  if (typeof cb === "function") cb();
32
+ } catch (error) {
33
+ console.error(
34
+ `[SystemLynx][ClientModule]: Failed to reconnect service @${connData.serviceUrl}`
35
+ );
36
+ }
37
+
31
38
  };
32
39
  const protocol = getProtocol(serviceUrl);
33
40
  methods.forEach(({ method, fn }) => {
@@ -58,11 +58,13 @@ module.exports = function ServiceRequestHandler(
58
58
  if (err.SystemLynxService) {
59
59
  cb(err);
60
60
  } else if (errCount <= 3) {
61
- console.log(err);
62
61
  errCount++;
63
62
  if (reconnectModule) reconnectModule(() => tryRequest(cb, errCount));
64
- else Service.reconnectService(() => tryRequest(cb, errCount));
65
- } else console.error(Error(`[SystemLynx][Service][Error]: Invalid route:${err}`));
63
+ else Service.resetConnection(() => tryRequest(cb, errCount));
64
+ } else {
65
+ console.error(`[SystemLynx][ServiceRequestHandler][Error]: ${err.message}\n`);
66
+ console.error(err);
67
+ }
66
68
  };
67
69
 
68
70
  return new Promise((resolve, reject) =>
@@ -14,7 +14,7 @@ module.exports = function loadConnectionData(
14
14
  setTimeout(() => getData(resolve, reject), errors.length * wait);
15
15
  else {
16
16
  console.error(
17
- `[SystemLynx][Client][Error]: Failed to load Service @${url} after ${errors.length} attempts.`
17
+ `[SystemLynx][Client]: Failed to load Service @${url} after ${errors.length} attempts.\n`
18
18
  );
19
19
  reject(err);
20
20
  }
@@ -78,7 +78,7 @@ module.exports = function createServerManager(customServer, customWebSocketServe
78
78
  return new Promise((resolve) => {
79
79
  const _server = ssl ? createSSLServer(server, ssl) : server;
80
80
  _server.listen(port, () => {
81
- console.log(`[SystemLynx][Service]: Listening on ${serviceUrl}`);
81
+ console.log(`[SystemLynx][Service]: Listening on ${serviceUrl}\n`);
82
82
  moduleQueue.forEach(({ name, Module, reserved_methods }) =>
83
83
  ServerManager.addModule(name, Module, reserved_methods)
84
84
  );
@@ -69,7 +69,7 @@ module.exports = function createRouter(server, config) {
69
69
 
70
70
  if (typeof Module[fn] !== "function")
71
71
  return sendResponse({
72
- message: `[SystemLynx][error]:${module_name}.${fn} method not found`,
72
+ message: `[SystemLynx][Router][Error]:${module_name}.${fn} method not found`,
73
73
  status: 404,
74
74
  });
75
75
 
@@ -42,7 +42,7 @@ module.exports = function createService(
42
42
 
43
43
  if (typeof constructor === "function") {
44
44
  if (constructor.constructor.name === "AsyncFunction")
45
- throw `[SystemLynx][Module][Error]: Module(name, constructor) function cannot receive an async function as the constructor`;
45
+ throw `[SystemLynx][Service][Error]: Module(name, constructor) function cannot receive an async function as the constructor`;
46
46
 
47
47
  const Module = createDispatcher.apply({ ...systemContext, before }, [
48
48
  undefined,