Added error catching.

pull/144/head
Mikunj 5 years ago
parent f21d1f65e6
commit 9b71e8119e

@ -52,4 +52,4 @@ stylesheets/_intlTelInput.scss
# Coverage
coverage/**
.nyc_output/**
.nyc_output/**

@ -23,7 +23,13 @@ class LocalLokiServer extends EventEmitter {
body.push(chunk);
})
.on('end', () => {
body = Buffer.concat(body).toString();
try {
body = Buffer.concat(body).toString();
} catch (e) {
// Error occurred while converting to string
res.statusCode = 500;
res.end();
}
// Check endpoints here
if (req.url === '/store') {

@ -75,21 +75,29 @@
};
this.handleMessage = message => {
const dataPlaintext = stringToArrayBufferBase64(message);
const messageBuf = textsecure.protobuf.WebSocketMessage.decode(
dataPlaintext
);
if (
messageBuf.type === textsecure.protobuf.WebSocketMessage.Type.REQUEST
) {
handleRequest(
new IncomingHttpResponse({
verb: messageBuf.request.verb,
path: messageBuf.request.path,
body: messageBuf.request.body,
id: messageBuf.request.id,
})
try {
const dataPlaintext = stringToArrayBufferBase64(message);
const messageBuf = textsecure.protobuf.WebSocketMessage.decode(
dataPlaintext
);
if (
messageBuf.type === textsecure.protobuf.WebSocketMessage.Type.REQUEST
) {
handleRequest(
new IncomingHttpResponse({
verb: messageBuf.request.verb,
path: messageBuf.request.path,
body: messageBuf.request.body,
id: messageBuf.request.id,
})
);
}
} catch (error) {
const info = {
message,
error: error.message,
};
window.log.warn('HTTP-Resources Failed to handle message:', info);
}
};

@ -89,7 +89,7 @@ MessageReceiver.prototype.extend({
this.localServer
.start(0)
.then(port =>
window.log.info(`Local Server started at https://localhost:${port}`)
window.log.info(`Local Server started at localhost:${port}`)
);
// TODO: Rework this socket stuff to work with online messaging

Loading…
Cancel
Save