Skip to content

Commit a6604df

Browse files
committed
Optimize and protect destructuring assignments
Closes: #162 PR-URL: #170
1 parent 68efa37 commit a6604df

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

server.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ const options = { trackUnmanagedFds: true };
1212

1313
(async () => {
1414
const config = await new Config(CFG_PATH);
15-
const { sections } = config;
16-
const count = sections.server.ports.length;
15+
const count = config.sections.server.ports.length;
1716
const workers = new Array(count);
1817

1918
const start = id => {

static/metacom.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export class Metacom {
99
const packet = JSON.parse(data);
1010
const { callback, event } = packet;
1111
const callId = callback || event;
12-
const [resolve, reject] = this.calls.get(callId);
12+
const promised = this.calls.get(callId);
13+
if (!promised) return;
14+
const [resolve, reject] = promised;
1315
if (packet.error) {
1416
const { code, message } = packet.error;
1517
const error = new Error(message);
@@ -39,9 +41,8 @@ export class Metacom {
3941
headers: { 'Content-Type': 'application/json' },
4042
body: JSON.stringify(packet),
4143
}).then(res => {
42-
const { status } = res;
43-
if (status === 200) return res.json().then(({ result }) => result);
44-
throw new Error(`Status Code: ${status}`);
44+
if (res.status === 200) return res.json().then(({ result }) => result);
45+
throw new Error(`Status Code: ${res.status}`);
4546
});
4647
};
4748
}

0 commit comments

Comments
 (0)