Skip to content

Commit

Permalink
docs(samples): updated samples code to use async await (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenqlogic authored and JustinBeckwith committed Nov 20, 2018
1 parent 2e48c0c commit 73786eb
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions samples/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,22 @@ const app = express();
const DISCOVERY_URL = 'https://www.googleapis.com/discovery/v1/apis';

// This incoming HTTP request should be captured by Trace
app.get('/', (req, res) => {
// This outgoing HTTP request should be captured by Trace
got(DISCOVERY_URL, { json: true })
.then((response) => {
const names = response.body.items.map((item) => item.name);

res
.status(200)
.send(names.join('\n'))
.end();
})
.catch((err) => {
console.error(err);
res
.status(500)
.end();
});
app.get('/', async (req, res) => {
// This outgoing HTTP request should be captured by Trace
try {
const { body } = await got(DISCOVERY_URL, { json: true });
const names = body.items.map((item) => item.name);
res
.status(200)
.send(names.join('\n'))
.end();
}
catch (err) {
console.error(err);
res
.status(500)
.end();
}
});

// Start the server
Expand Down

0 comments on commit 73786eb

Please sign in to comment.