Skip to content

Commit

Permalink
fix: remove redundant try-catch from http/https server examples (#2195)
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas authored May 10, 2021
1 parent 9ce9eea commit 1218a3c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
26 changes: 11 additions & 15 deletions examples/http/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,17 @@ function handleRequest(request, response) {
});
// Annotate our span to capture metadata about the operation
span.addEvent('invoking handleRequest');
try {
const body = [];
request.on('error', (err) => console.log(err));
request.on('data', (chunk) => body.push(chunk));
request.on('end', () => {
// deliberately sleeping to mock some action.
setTimeout(() => {
span.end();
response.end('Hello World!');
}, 2000);
});
} catch (err) {
console.error(err);
span.end();
}

const body = [];
request.on('error', (err) => console.log(err));
request.on('data', (chunk) => body.push(chunk));
request.on('end', () => {
// deliberately sleeping to mock some action.
setTimeout(() => {
span.end();
response.end('Hello World!');
}, 2000);
});
}

startServer(8080);
26 changes: 11 additions & 15 deletions examples/https/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,17 @@ function handleRequest(request, response) {
});
// Annotate our span to capture metadata about the operation
span.addEvent('invoking handleRequest');
try {
const body = [];
request.on('error', (err) => console.log(err));
request.on('data', (chunk) => body.push(chunk));
request.on('end', () => {
// deliberately sleeping to mock some action.
setTimeout(() => {
span.end();
response.end('Hello World!');
}, 2000);
});
} catch (err) {
console.log(err);
span.end();
}

const body = [];
request.on('error', (err) => console.log(err));
request.on('data', (chunk) => body.push(chunk));
request.on('end', () => {
// deliberately sleeping to mock some action.
setTimeout(() => {
span.end();
response.end('Hello World!');
}, 2000);
});
}

startServer(443);

0 comments on commit 1218a3c

Please sign in to comment.